cURL / Mailing Lists / curl-library / Single Mail


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

From: Daniel Stenberg <>
Date: Tue, 1 Oct 2002 17:10:59 +0200 (MET DST)

On Tue, 1 Oct 2002, Holger Rauch wrote:

> Even after having read the curl_formadd() man page, the difference between
> is not clear to me.

I know the curl_formadd man page isn't very well structured. I'll welcome all
kinds of improvements anyone can provide.

> 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.

PTRCONTENTS means that you only pass the pointer to libcurl, and it'll refer
to the same data you pointed to. COPYCONTENTS will make libcurl copy that
data, and thus you can remove it immediately after having called
curl_formadd(), if that's what you want.

Needless to say, PTRCONTENTS will be a lot faster and less resourse-hungry
especially if you plan to send away large chunks of data.

> 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,

COPYNAME copies the string (which we can see isn't needed here).

BUFFER sets a name for the buffer upload. This name is what the "filename"
will be set to, as this is a "file upload" kind of form.

BUFFERPTR points out the buffer to send off, looking like a file upload.

BUFFERLENGTH is the size of the data to file upload.

A file upload field has a name, a file name and a contents part.

> Is this equivalent to (provided that "record" is omitted)
> curl_formadd(&post, &last,

COPYNAME copies the string

PTRCONTENTS points to the data.

This will only make a form field that is "name=data".

> curl_formadd(&post, &last,

The only difference here is that this COPYCONTENTS copies the data part too.

> curl_formadd(&post, &last,

This makes it a file upload part, as that's what BUFFERPTR implies. I believe
this particular use of the function will return an error code, as you haven't
provided a BUFFER to name the file in this faked file upload.

> Get the point I'm trying to make?

I think so.

> Could anybody please enlighten me when to use which of these options?

I hope this mail has clarified it somewhat. Please ask again if it didn't.
Also, if you try to tell us what you want to do, it might be easier to tell
you how curl_formadd() is meant to be used for that purpose.

 Daniel Stenberg -- curl related mails on curl related mailing lists please
This email is sponsored by: DEDICATED SERVERS only $89!
Linux or FreeBSD, FREE setup, FAST network. Get your own server 
today at
Received on 2002-10-01