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