cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Saving binary data

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 15 Jan 2014 21:03:37 +0100

On Wed, Jan 15, 2014 at 10:06:18AM -0500, Jerry Geis wrote:
> I am using curl with --data-binary to transfer a data file.
>
> On the server side I have this:
>        # Read in all DATA from stdin
>         if [ "$REQUEST_METHOD" = "POST" ]
>         then
>                 if [ "$CONTENT_LENGTH" -gt 0 ]
>                 then
>                         Logging "$MACHINE" "$REFERENCE" "Received total
> $CONTENT_LENGTH"
>                         read -N $CONTENT_LENGTH POST_DATA <&0
>                 fi
>         fi
>
>
> echo -nE "$POST_DATA" > $TMP_FILE
>
>
> However my binary data that  I sent does not match.
> SOMETHING in my saving of the data (POST_DATA) is 
> modifying the data. There is a backslash in the data and that 
> seems to be messing things up. The echo above with a backslash 
> I think is the problem.
>
> How do I just "save" the data as is in a bash  CGI script? 

This isn't really a curl question. --data-binary will send the data as-is, so
as you suspect, it's likely a server-side problem. read will process
backslashes, as you found. Something like

  dd bs="$CONTENT_LENGTH" count=1 of="$TMP_FILE"

should work better in this case.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-01-15