cURL / Mailing Lists / curl-library / Single Mail

curl-library

Sending in chunks

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 9 Jan 2012 00:19:10 -0800

On Mon, Jan 09, 2012 at 10:41:49AM +0530, Brad Mann wrote:
> By chunks I mean that I am sending the file in parts, i.e. chunks of
> 512 (as directed in the documentation) . I am using the following
> code:-

That doesn't help any. "chunks" has a well-defined meaning in HTTP, but
it doesn't sounds like you're using it that way, and "parts" is used in
several contexts in the HTTP spec, and it not clear which one you mean.
Did you mean to say 512 KiB? That would match the code samples you give,
and implies that you're talking about "part" in the sense of "a range of"
and don't mean to say "chunk" in the HTTP sense at all.

If that's true, then libcurl's automatic headers based on CURLOPT_RESUME_FROM
and CURLOPT_INFILESIZE_LARGE aren't quite what you want. Even
CURLOPT_RANGE and CURLOPT_INFILESIZE_LARGE probably won't quite work, either,
in which case you'll have to generate the Content-Range header yourself
(as you've done). CURLOPT_INFILESIZE_LARGE should still work properly to
set the Content-Length: header, though.

> vector<string> request_headers2;
>
> request_headers2.push_back("Content-Length: 524288");
> request_headers2.push_back("Content-Range: bytes 0-524287/" + strFileSize);
> request_headers2.push_back("Accept:");
>
> strGoogleResponseUP = "";
>
> struct curl_slist *header_text = NULL;
>
> // Add standard headers
> for (unsigned int i = 0; i < request_headers2.size(); ++i)
> {
> header_text = curl_slist_append(header_text, request_headers2[i].c_str());
> }
> // Add standard headers
>
> curl_easy_setopt(curl,CURLOPT_URL, strURLWithID.c_str()); //version 3 url.
> curl_easy_setopt(curl,CURLOPT_HEADER, true);

N.B., the value here must be a long, not a bool.

> curl_easy_setopt(curl,CURLOPT_HTTPHEADER,header_text);
> curl_easy_setopt(curl, CURLOPT_PUT, 1L);
> curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST, 0L);
> curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,false); //skipping peer

Same here.

> verification
> curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
> curl_easy_setopt(curl, CURLOPT_READDATA, pFile);
>
> res = curl_easy_perform(curl);
>
> The response is NULL in the case of Content-Length and Content-Range tags...

What response is NULL? What is the error code returned? What is the
resultantant behaviour of this code ? Also, what version of libcurl are you
using?

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-01-09