cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: artificial file upload part with curl_formadd()

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 20 Aug 2003 08:48:56 +0200 (CEST)

On Tue, 19 Aug 2003, Mohun Biswas wrote:

> I'm using libcurl (7.10.6) to do a multipart file upload and it works fine.
> But now I want one of those parts to be "fake"; in other words it should
> look just like every other file upload part except that the contents do not
> come from a file but rather from a buffer which I provide. The part would
> look like this
>
> Content-Disposition: form-data; name="foo";\ filename="/full/path/to/foo"
> Content-Type: application/binary
>
> <data from a buffer, not from file "foo">
>
> All the examples I can find show only how to do a "real" file upload. I've
> tried various permutations without success. In particular the documentation
> for CURLFORM_BUFFER ("followed by a string, tells libcurl that a buffer is
> to be used to upload data instead of using a file..." sounds good, e.g.
>
> res = curl_formadd(&(glb->hg_formpost), &(glb->hg_lastptr),
> CURLFORM_BUFFER, pnp->pn_path,
> CURLFORM_BUFFERPTR, strdup(lnkbuf),
> CURLFORM_CONTENTTYPE, "application/binary",
> CURLFORM_END);
>
> Can anyone give a sample curl_formadd() invocation for this?

There is in fact an example of this in the curl_formadd() man page that looks
like this:

 /* Add a buffer to upload */
 curl_formadd(&post, &last,
              CURLFORM_COPYNAME, "name",
              CURLFORM_BUFFER, "data",
              CURLFORM_BUFFERPTR, record,
              CURLFORM_BUFFERLENGTH, record_length,
              CURLFORM_END);

'name' is the name of this part, 'data' is the name set in the file name
field.

-- 
 Daniel Stenberg -- curl: been grokking URLs since 1998
-------------------------------------------------------
This SF.net email is sponsored by Dice.com.
Did you know that Dice has over 25,000 tech jobs available today? From
careers in IT to Engineering to Tech Sales, Dice has tech jobs from the
best hiring companies. http://www.dice.com/index.epl?rel_code=104
Received on 2003-08-20