Bash – using CURL to transmit binary data over POST parameter

bashbinarycurldatalinux

How can i use CURL to send binary data through a specific post parameter?
E.g in:

curl 'http://www.example.com' -H 'hi:hi' --data 'utf8=%E2%9C%93&_method=put&file=binarydatahere&submit=confirm'

I want to send the binary data through the file parameter, I've heard of the --data-binary @myfile.bin method, but i fail to see how i can specify to which parameter the binary data goes through.

Best Answer

Put the name of the parameter in front of the @, like this:

--data-binary file@myfile.bin

From the curl manpage:

name@filename This will make curl load data from the given file (including any newlines), URL-encode that data and pass it on in the POST. The name part gets an equal sign appended, resulting in name=urlencoded-file-content. Note that the name is expected to be URL-encoded already.

Related Question