block by joyrexus 8ea8fe71932dda48e554

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