Is it possible to upload a file with cURL from a pipe? Is it possible to upload a file with cURL from a pipe? curl curl

Is it possible to upload a file with cURL from a pipe?


Yes it is possible!

By default, curl will check all the provided arguments, figure out the size of all involved components (including the files) and send them in the constructed POST request. That means curl will check the size of the local file, which thus breaks when you use a fifo. Thus you need to do something about it!

chunked for fifo

By telling curl it should do the POST with chunked encoding instead of providing the full size ahead of time, curl will instead read the file in a streaming manner and just allow it to turn up to be whatever size it needs to be at the time the file (fifo) is read.

You can do this by setting the chunked header, which is used by curl as a signal to do the request chunked.

curl -H "Tranfer-Encoding: chunked" -F file=@fifo https://example.com

caveat

The reason this isn't the default behavior by curl is that this requires that the receiver is using HTTP/1.1 or later (which curl doesn't know until it gets the response back from the server). Old HTTP/1.0 servers don't speak "chunk".

formpost from stdin

When doing a formpost from stdin, curl will read the entire file off stdin first in memory, before doing the POST, to get the size of the content so that it can include that in the POST request.