cURL / Mailing Lists / curl-library / Single Mail

curl-library

(no subject)

From: Brad Mann <bradcharlesmann_at_gmail.com>
Date: Fri, 6 Jan 2012 17:56:55 +0530

Hi Folks,

I am implementing Google docs functionality in my application using
libcurl and for the same I need to send the file in chunks to their
server. Problem is that I am not able to do the same. Below is the
code :

I am using VC++ .

//Open the file and read it in a buffer.
//The first chunk
FILE *pFile;
pFile = fopen(post_data.filename.c_str(),"r");

request_headers2.push_back("Content-Length: 524288");
///request_headers2.push_back("Content-Length: 262144");
///request_headers2.push_back("Content-Range: bytes 0-262143/" + strFileSize);
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_UPLOAD, 1L);
curl_easy_setopt(curl,CURLOPT_URL, strURLWithID.c_str()); //version 3 url.
//curl_easy_setopt(curl, CURLOPT_RANGE, "0-524287");
curl_easy_setopt(curl,CURLOPT_HEADER, true);
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
verification
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, pFile);

res = curl_easy_perform(curl);

//The second chunk

fseek(pFile,524288,SEEK_SET);

vector<string> request_headers3;

request_headers3.push_back("Content-Length: 524288");
request_headers3.push_back("Content-Range: bytes 524288-1048575/" +
strFileSize);
///request_headers3.push_back("Content-Length: 262144");
///request_headers3.push_back("Content-Range: bytes 262144-524287/" +
strFileSize);
request_headers3.push_back("Accept:");

struct curl_slist *header_text2 = NULL;

// Add standard headers
for (unsigned int i = 0; i < request_headers3.size(); ++i)
{
  header_text2 = curl_slist_append(header_text2, request_headers3[i].c_str());
}
// Add standard headers

strGoogleResponseUP = "";

//curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl,CURLOPT_URL, strURLWithID.c_str()); //version 3 url.
//curl_easy_setopt(curl, CURLOPT_RANGE, "524288-1048575");
curl_easy_setopt(curl, CURLOPT_APPEND, 1L);
curl_easy_setopt(curl,CURLOPT_HEADER, true);
curl_easy_setopt(curl,CURLOPT_HTTPHEADER,header_text2);
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
verification
//curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)pooh.sizeleft);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, pFile);

res = curl_easy_perform(curl);

I am using VC++ for the same.
Please help me on this..Is there any example for uploading the file in chunks..?

Thanks,
Brad
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-01-06