yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | Long: form |
| 2 | Short: F |
| 3 | Arg: <name=content> |
| 4 | Help: Specify HTTP multipart POST data |
| 5 | Protocols: HTTP |
| 6 | Mutexed: data head upload |
| 7 | --- |
| 8 | This lets curl emulate a filled-in form in which a user has pressed the submit |
| 9 | button. This causes curl to POST data using the Content-Type |
| 10 | multipart/form-data according to RFC 2388. This enables uploading of binary |
| 11 | files etc. To force the 'content' part to be a file, prefix the file name with |
| 12 | an @ sign. To just get the content part from a file, prefix the file name with |
| 13 | the symbol <. The difference between @ and < is then that @ makes a file get |
| 14 | attached in the post as a file upload, while the < makes a text field and just |
| 15 | get the contents for that text field from a file. |
| 16 | |
| 17 | Example: to send an image to a server, where \&'profile' is the name of the |
| 18 | form-field to which portrait.jpg will be the input: |
| 19 | |
| 20 | curl -F profile=@portrait.jpg https://example.com/upload.cgi |
| 21 | |
| 22 | To read content from stdin instead of a file, use - as the filename. This goes |
| 23 | for both @ and < constructs. Unfortunately it does not support reading the |
| 24 | file from a named pipe or similar, as it needs the full size before the |
| 25 | transfer starts. |
| 26 | |
| 27 | You can also tell curl what Content-Type to use by using 'type=', in a manner |
| 28 | similar to: |
| 29 | |
| 30 | curl -F "web=@index.html;type=text/html" example.com |
| 31 | |
| 32 | or |
| 33 | |
| 34 | curl -F "name=daniel;type=text/foo" example.com |
| 35 | |
| 36 | You can also explicitly change the name field of a file upload part by setting |
| 37 | filename=, like this: |
| 38 | |
| 39 | curl -F "file=@localfile;filename=nameinpost" example.com |
| 40 | |
| 41 | If filename/path contains ',' or ';', it must be quoted by double-quotes like: |
| 42 | |
| 43 | curl -F "file=@\\"localfile\\";filename=\\"nameinpost\\"" example.com |
| 44 | |
| 45 | or |
| 46 | |
| 47 | curl -F 'file=@"localfile";filename="nameinpost"' example.com |
| 48 | |
| 49 | Note that if a filename/path is quoted by double-quotes, any double-quote |
| 50 | or backslash within the filename must be escaped by backslash. |
| 51 | |
| 52 | See further examples and details in the MANUAL. |
| 53 | |
| 54 | This option can be used multiple times. |