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