cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Differences between the buffer-oriented curl_fromadd() parameters

From: Combes, Chris M. <ccombes_at_northropgrumman.com>
Date: Tue, 01 Oct 2002 09:53:34 -0400

Hi Holger,

The differences between the options are somewhat subtle.

Options CURLFORM_BUFFER, CURLFORM_BUFFERPTR, and CURLFORM_BUFFERLENGTH
are all used together to signify that an "upload" is taking place.

This means that not only is a "name" field added to the multipart form,
but a "filename" field is added as well, so that a server will know that
a client is uploading a file.

CURLFORM_COPYNAME - Tells curl to copy the next parameter as the name of the
field for the multipart form.

CURLFORM_BUFFER - Tells curl that you plan to upload a buffer, with the
next parameter signifying the "filename". In the example below "name".

CURLFORM_BUFFERPTR - A pointer to the contents of this data (e.g. a character
pointer).

CURLFORM_BUFFERLENGTH - The size of this buffer, since the above pointer can
point to binary data, and curl needs to know how many bytes to read from the
pointer.

CURLFORM_PTRCONTENTS is similar to reading the data as with the BUFFER options,
but does not add the filename="data" parameter to the multipart form.

The BUFFER terms are used to signify a distinct operation, and
the code base supporting this method better than mixing options. Perhaps the
number of options can be decreased to make it easier on the user.

Also, BUFFER was used so that the user can upload data from memory, instead of
having to specify a filename, that is read by curl (e.g. CURLFORM_FILE).

I understand that CURLFORM_COPYCONTENTS is used to copy string data into curl,
so that the user can free the referenced memory.

I hope this helps. If anyone has corrections to the above, please send.

Chris

Holger Rauch wrote:
> Hi!
>
> Even after having read the curl_formadd() man page, the difference between
>
> - CURLFORM_BUFFER
> - CURLFORM_BUFFERPTR
> - CURLFORM_COPYCONTENTS
> - CURLFORM_PTRCONTENTS
>
> is not clear to me. I realize that when using CURLFORM_BUFFERPTR, I must
> make sure that the data is available until curl_easy_cleanup() has
> performed its job. For CURLFORM_PTRCONTENTS, it's only mentioned that an
> optional length parameter may be specified, but I don't see the difference
> to CURLFORM_COPYCONTENTS, for example. Does the following command (taken
> from the example in the man page) upload two buffers (data AND
> record)? ("record" doesn't seem to specified in the example, so I don't
> know what it is.)
>
> curl_formadd(&post, &last,
> CURLFORM_COPYNAME, "name",
> CURLFORM_BUFFER, "data",
> CURLFORM_BUFFERPTR, record,
> CURLFORM_BUFFERLENGTH, record_length,
> CURLFORM_END);
>
> Is this equivalent to (provided that "record" is omitted)
>
> curl_formadd(&post, &last,
> CURLFORM_COPYNAME, "name",
> CURLFORM_PTRCONTENTS, "data",
> CURLFORM_END);
>
> or
>
> curl_formadd(&post, &last,
> CURLFORM_COPYNAME, "name",
> CURLFORM_COPYCONTENTS, "data",
> CURLFORM_END);
>
> or
>
> curl_formadd(&post, &last,
> CURLFORM_COPYNAME, "name",
> CURLFORM_BUFFERPTR, "data",
> CURLFORM_END);
>
> Get the point I'm trying to make?
>
> Could anybody please enlighten me when to use which of these options?
>
>
> Thanks in advance for any info!
>
> Kind regards,
>
> Holger
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by: DEDICATED SERVERS only $89!
> Linux or FreeBSD, FREE setup, FAST network. Get your own server
> today at http://www.ServePath.com/indexfm.htm
>

-------------------------------------------------------
This sf.net email is sponsored by: DEDICATED SERVERS only $89!
Linux or FreeBSD, FREE setup, FAST network. Get your own server
today at http://www.ServePath.com/indexfm.htm
Received on 2002-10-01