Bash curl POST a binary variable Bash curl POST a binary variable curl curl

Bash curl POST a binary variable


Try to eliminate the variable ... as follows:

curl "http://www.google.com/images/srpr/logo3w.png" | curl --data-binary - --request "POST" "http://www.somesite.com"

From the curl man page:

If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin.

EDIT: From the man page, too:

--raw When used, it disables all internal HTTP decoding of content or transfer encodings and instead makes them passed on unaltered, raw. (Added in 7.16.2)

What happens, if applied on either or both sides?


I had a related problem, where I wanted to dynamically curl a file from a given folder.

curl --data-binary directory/$file --request "POST" "http://www.somesite.com"did not work - uploaded the string "directory/myFile.jar" instead of the actual file.

Adding the @ symbolcurl --data-binary @directory/$file --request "POST" "http://www.somesite.com" fixed it.