1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerLong: form 5*6236dae4SAndroid Build Coastguard WorkerShort: F 6*6236dae4SAndroid Build Coastguard WorkerArg: <name=content> 7*6236dae4SAndroid Build Coastguard WorkerHelp: Specify multipart MIME data 8*6236dae4SAndroid Build Coastguard WorkerProtocols: HTTP SMTP IMAP 9*6236dae4SAndroid Build Coastguard WorkerMutexed: data head upload-file 10*6236dae4SAndroid Build Coastguard WorkerCategory: http upload post imap smtp 11*6236dae4SAndroid Build Coastguard WorkerAdded: 5.0 12*6236dae4SAndroid Build Coastguard WorkerMulti: append 13*6236dae4SAndroid Build Coastguard WorkerSee-also: 14*6236dae4SAndroid Build Coastguard Worker - data 15*6236dae4SAndroid Build Coastguard Worker - form-string 16*6236dae4SAndroid Build Coastguard Worker - form-escape 17*6236dae4SAndroid Build Coastguard WorkerExample: 18*6236dae4SAndroid Build Coastguard Worker - --form "name=curl" --form "file=@loadthis" $URL 19*6236dae4SAndroid Build Coastguard Worker--- 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker# `--form` 22*6236dae4SAndroid Build Coastguard Worker 23*6236dae4SAndroid Build Coastguard WorkerFor the HTTP protocol family, emulate a filled-in form in which a user has 24*6236dae4SAndroid Build Coastguard Workerpressed the submit button. This makes curl POST data using the Content-Type 25*6236dae4SAndroid Build Coastguard Workermultipart/form-data according to RFC 2388. 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard WorkerFor SMTP and IMAP protocols, this composes a multipart mail message to 28*6236dae4SAndroid Build Coastguard Workertransmit. 29*6236dae4SAndroid Build Coastguard Worker 30*6236dae4SAndroid Build Coastguard WorkerThis enables uploading of binary files etc. To force the 'content' part to be 31*6236dae4SAndroid Build Coastguard Workera file, prefix the filename with an @ sign. To just get the content part from 32*6236dae4SAndroid Build Coastguard Workera file, prefix the filename with the symbol \<. The difference between @ and 33*6236dae4SAndroid Build Coastguard Worker\< is then that @ makes a file get attached in the post as a file upload, 34*6236dae4SAndroid Build Coastguard Workerwhile the \< makes a text field and just get the contents for that text field 35*6236dae4SAndroid Build Coastguard Workerfrom a file. 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard WorkerRead content from stdin instead of a file by using a single "-" as filename. 38*6236dae4SAndroid Build Coastguard WorkerThis goes for both @ and \< constructs. When stdin is used, the contents is 39*6236dae4SAndroid Build Coastguard Workerbuffered in memory first by curl to determine its size and allow a possible 40*6236dae4SAndroid Build Coastguard Workerresend. Defining a part's data from a named non-regular file (such as a named 41*6236dae4SAndroid Build Coastguard Workerpipe or similar) is not subject to buffering and is instead read at 42*6236dae4SAndroid Build Coastguard Workertransmission time; since the full size is unknown before the transfer starts, 43*6236dae4SAndroid Build Coastguard Workersuch data is sent as chunks by HTTP and rejected by IMAP. 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard WorkerExample: send an image to an HTTP server, where 'profile' is the name of the 46*6236dae4SAndroid Build Coastguard Workerform-field to which the file **portrait.jpg** is the input: 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard Worker curl -F profile=@portrait.jpg https://example.com/upload.cgi 49*6236dae4SAndroid Build Coastguard Worker 50*6236dae4SAndroid Build Coastguard WorkerExample: send your name and shoe size in two text fields to the server: 51*6236dae4SAndroid Build Coastguard Worker 52*6236dae4SAndroid Build Coastguard Worker curl -F name=John -F shoesize=11 https://example.com/ 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerExample: send your essay in a text field to the server. Send it as a plain 55*6236dae4SAndroid Build Coastguard Workertext field, but get the contents for it from a local file: 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard Worker curl -F "story=<hugefile.txt" https://example.com/ 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard WorkerYou can also instruct curl what Content-Type to use by using `type=`, in a 60*6236dae4SAndroid Build Coastguard Workermanner similar to: 61*6236dae4SAndroid Build Coastguard Worker 62*6236dae4SAndroid Build Coastguard Worker curl -F "web=@index.html;type=text/html" example.com 63*6236dae4SAndroid Build Coastguard Worker 64*6236dae4SAndroid Build Coastguard Workeror 65*6236dae4SAndroid Build Coastguard Worker 66*6236dae4SAndroid Build Coastguard Worker curl -F "name=daniel;type=text/foo" example.com 67*6236dae4SAndroid Build Coastguard Worker 68*6236dae4SAndroid Build Coastguard WorkerYou can also explicitly change the name field of a file upload part by setting 69*6236dae4SAndroid Build Coastguard Workerfilename=, like this: 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker curl -F "file=@localfile;filename=nameinpost" example.com 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard WorkerIf filename/path contains ',' or ';', it must be quoted by double-quotes like: 74*6236dae4SAndroid Build Coastguard Worker 75*6236dae4SAndroid Build Coastguard Worker curl -F "file=@\"local,file\";filename=\"name;in;post\"" \ 76*6236dae4SAndroid Build Coastguard Worker https://example.com 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard Workeror 79*6236dae4SAndroid Build Coastguard Worker 80*6236dae4SAndroid Build Coastguard Worker curl -F 'file=@"local,file";filename="name;in;post"' \ 81*6236dae4SAndroid Build Coastguard Worker https://example.com 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard WorkerNote that if a filename/path is quoted by double-quotes, any double-quote 84*6236dae4SAndroid Build Coastguard Workeror backslash within the filename must be escaped by backslash. 85*6236dae4SAndroid Build Coastguard Worker 86*6236dae4SAndroid Build Coastguard WorkerQuoting must also be applied to non-file data if it contains semicolons, 87*6236dae4SAndroid Build Coastguard Workerleading/trailing spaces or leading double quotes: 88*6236dae4SAndroid Build Coastguard Worker 89*6236dae4SAndroid Build Coastguard Worker curl -F 'colors="red; green; blue";type=text/x-myapp' \ 90*6236dae4SAndroid Build Coastguard Worker https://example.com 91*6236dae4SAndroid Build Coastguard Worker 92*6236dae4SAndroid Build Coastguard WorkerYou can add custom headers to the field by setting headers=, like 93*6236dae4SAndroid Build Coastguard Worker 94*6236dae4SAndroid Build Coastguard Worker curl -F "submit=OK;headers=\"X-submit-type: OK\"" example.com 95*6236dae4SAndroid Build Coastguard Worker 96*6236dae4SAndroid Build Coastguard Workeror 97*6236dae4SAndroid Build Coastguard Worker 98*6236dae4SAndroid Build Coastguard Worker curl -F "submit=OK;headers=@headerfile" example.com 99*6236dae4SAndroid Build Coastguard Worker 100*6236dae4SAndroid Build Coastguard WorkerThe headers= keyword may appear more that once and above notes about quoting 101*6236dae4SAndroid Build Coastguard Workerapply. When headers are read from a file, Empty lines and lines starting 102*6236dae4SAndroid Build Coastguard Workerwith '#' are comments and ignored; each header can be folded by splitting 103*6236dae4SAndroid Build Coastguard Workerbetween two words and starting the continuation line with a space; embedded 104*6236dae4SAndroid Build Coastguard Workercarriage-returns and trailing spaces are stripped. 105*6236dae4SAndroid Build Coastguard WorkerHere is an example of a header file contents: 106*6236dae4SAndroid Build Coastguard Worker 107*6236dae4SAndroid Build Coastguard Worker # This file contain two headers. 108*6236dae4SAndroid Build Coastguard Worker X-header-1: this is a header 109*6236dae4SAndroid Build Coastguard Worker 110*6236dae4SAndroid Build Coastguard Worker # The following header is folded. 111*6236dae4SAndroid Build Coastguard Worker X-header-2: this is 112*6236dae4SAndroid Build Coastguard Worker another header 113*6236dae4SAndroid Build Coastguard Worker 114*6236dae4SAndroid Build Coastguard WorkerTo support sending multipart mail messages, the syntax is extended as follows: 115*6236dae4SAndroid Build Coastguard Worker 116*6236dae4SAndroid Build Coastguard Worker- name can be omitted: the equal sign is the first character of the argument, 117*6236dae4SAndroid Build Coastguard Worker 118*6236dae4SAndroid Build Coastguard Worker- if data starts with '(', this signals to start a new multipart: it can be 119*6236dae4SAndroid Build Coastguard Workerfollowed by a content type specification. 120*6236dae4SAndroid Build Coastguard Worker 121*6236dae4SAndroid Build Coastguard Worker- a multipart can be terminated with a '=)' argument. 122*6236dae4SAndroid Build Coastguard Worker 123*6236dae4SAndroid Build Coastguard WorkerExample: the following command sends an SMTP mime email consisting in an 124*6236dae4SAndroid Build Coastguard Workerinline part in two alternative formats: plain text and HTML. It attaches a 125*6236dae4SAndroid Build Coastguard Workertext file: 126*6236dae4SAndroid Build Coastguard Worker 127*6236dae4SAndroid Build Coastguard Worker curl -F '=(;type=multipart/alternative' \ 128*6236dae4SAndroid Build Coastguard Worker -F '=plain text message' \ 129*6236dae4SAndroid Build Coastguard Worker -F '= <body>HTML message</body>;type=text/html' \ 130*6236dae4SAndroid Build Coastguard Worker -F '=)' -F '=@textfile.txt' ... smtp://example.com 131*6236dae4SAndroid Build Coastguard Worker 132*6236dae4SAndroid Build Coastguard WorkerData can be encoded for transfer using encoder=. Available encodings are 133*6236dae4SAndroid Build Coastguard Worker*binary* and *8bit* that do nothing else than adding the corresponding 134*6236dae4SAndroid Build Coastguard WorkerContent-Transfer-Encoding header, *7bit* that only rejects 8-bit characters 135*6236dae4SAndroid Build Coastguard Workerwith a transfer error, *quoted-printable* and *base64* that encodes data 136*6236dae4SAndroid Build Coastguard Workeraccording to the corresponding schemes, limiting lines length to 76 137*6236dae4SAndroid Build Coastguard Workercharacters. 138*6236dae4SAndroid Build Coastguard Worker 139*6236dae4SAndroid Build Coastguard WorkerExample: send multipart mail with a quoted-printable text message and a 140*6236dae4SAndroid Build Coastguard Workerbase64 attached file: 141*6236dae4SAndroid Build Coastguard Worker 142*6236dae4SAndroid Build Coastguard Worker curl -F '=text message;encoder=quoted-printable' \ 143*6236dae4SAndroid Build Coastguard Worker -F '=@localfile;encoder=base64' ... smtp://example.com 144*6236dae4SAndroid Build Coastguard Worker 145*6236dae4SAndroid Build Coastguard WorkerSee further examples and details in the MANUAL. 146