curl-library
Re: Need clarification on tutorial
Date: Wed, 11 Jul 2012 09:31:57 +0400
On 07/10/2012 07:08 AM, Igor Korot wrote:
> The read callback should have a prototype similar to:
>
> size_t function(char *bufptr, size_t size, size_t nitems, void *userp);
>
> Where bufptr is the pointer to a buffer we fill in with data to upload
> and size*nitems is the size of the buffer and therefore also the
> maximum amount of data we can return to libcurl in this call. The
> 'userp' pointer is the custom pointer we set to point to a struct of
> ours to pass private data between the application and the callback.
>
> curl_easy_setopt(easyhandle, CURLOPT_READFUNCTION, read_function);
>
> curl_easy_setopt(easyhandle, CURLOPT_READDATA,&filedata);
>
> Tell libcurl that we want to upload:
>
> curl_easy_setopt(easyhandle, CURLOPT_UPLOAD, 1L);
> "
>
> Now in this piece if I'm reading correctly, "read_function =
> function". Is this correct?
yes. read_function stands for a function with signature "size_t
function(char *bufptr, size_t size, size_t nitems, void *userp);", which
is provided by the user.
>
> And "filedata = bufptr". Is this correct?
No. bufptr is a pointer to a char buffer allocated by libcurl. read
function is supposed to fill this buffer with the data to be uploaded.
filedata is an optional pointer, which user may want to associate with
the read_function, using curl_easy_setopt. The same pointer will be
available as userp param of the read_funciton callback. libcurl will not
touch this.
Along with the man pages, you can see the examples provided at
http://curl.haxx.se/libcurl/c/options-in-examples.html for the usages.
> Also on unrelated note.
> I need to perform multipart file transfer. The file is the bitmap and
> it will be transferred thru
> HTTP POST. However, prior to this I need to send 2 strings: one that
> will identify the beginning
> of the transfer (boundary) and another that will identify the name of the file.
> I will also need to send the boundary string at the end of the transfer.
>
> My question is: Is there a simple way of transferring the "char *"
> (string) or I will have to
> declare a callback and just assign the string to the data pointer
> according to the part
> I mentioned above.
There are examples for POST at the above link, which shows different usages.
-lijo
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-07-11