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