2
0

form.d 5.0 KB

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