cURL / Mailing Lists / curl-library / Single Mail

curl-library

How to POST binary data with libcurl?

From: Tillmann Steinbrecher <tsteinbr_at_igd.fraunhofer.de>
Date: Wed, 26 Jul 2006 20:03:07 +0200

Hi,

I have a very simple, basic problem; however despite reading of
documentation, mailing list archives, etc, I just can't find a solution.

What I'd like to do is simply POST binary data using libcurl, as a
normal multipart/formdata HTTP POST.

The problem that I have is that the data posted is truncated as soon as
the first zero byte occurs - as if strlen was being used; but DESPITE
the fact that I used CURLFORM_CONTENTSLENGTH in curl_formadd(). In fact,
the behaviour is very strange: It seems that libcurl either uses the
value provided after CURLFORM_CONTENTSLENGTH, OR the string length,
whichever is lower.

Example:

curl_formadd(&post, &last,
                CURLFORM_COPYNAME, "mydata",
                CURLFORM_PTRCONTENTS, "test\0test",
               CURLFORM_CONTENTSLENGTH, 9,
               CURLFORM_END);

-> 4 bytes are posted, but not 9

curl_formadd(&post, &last,
                CURLFORM_COPYNAME, "mydata",
                CURLFORM_PTRCONTENTS, "test\0test",
               CURLFORM_CONTENTSLENGTH, 2,
               CURLFORM_END);

-> 2 bytes are posted

Using CURLOPT_POSTFIELDSIZE doesn't seem to help either; as apparently
that option doesn't work with curl_formadd for creating rfc1867-style
(multipart) POSTs.

Any help would be greatly appreciated.

bye,
Till

-- 
Dipl.-Ing. Tillmann Steinbrecher        http://www.igd.fhg.de/~tsteinbr/
Cognitive Computing & Medical Imaging   Phone: +49 6151 155-485
Fraunhofer IGD, Fraunhoferstr. 5, D-64283 Darmstadt, Germany
Received on 2006-07-26