Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active September 1, 2023 02:46
Show Gist options
  • Save joyrexus/8ea8fe71932dda48e554 to your computer and use it in GitHub Desktop.
Save joyrexus/8ea8fe71932dda48e554 to your computer and use it in GitHub Desktop.
File upload POST with curl

Extracted from this excellent curl tutorial


Back in late 1995 they defined an additional way to post data over HTTP. It is documented in the RFC 1867, why this method sometimes is referred to as RFC1867-posting.

This method is mainly designed to better support file uploads. A form that allows a user to upload a file could be written like this in HTML:

<!DOCTYPE html>
<meta charset="utf-8">
<body>
  <form method="POST" action='/submit' enctype="multipart/form-data">
    <input type="text" name="user"><br>
    <input type="file" name="upload"><br>
    <input type="submit">
  </form>

This clearly shows that the Content-Type about to be sent is multipart/form-data.

To post a form like this with curl, you enter a command line like:

curl --form upload=@localfilename   \
     --form user=Melvin             \
     http://localhost:8080/submit

Server-side

To handle POST requests server-side, see the following multipart/form-data server demos:

See also

  • httpie - a python-based utility that's intended to be a more user-friendly replacement for curl.
@avenwu
Copy link

avenwu commented Jan 17, 2019

nice tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment