curl-library
File uploading problem
Date: Sat, 4 Oct 2008 20:01:03 +0530
Hi,
I am currently facing some problems in uploading the file using curl in
webkit....
I am using rapidshare.com for testing this code, and I am uploading file of
around 30-50 bytes.
In this before posting a request I m calculating the size of the request.
After calculating the size of the total contents, all the attributes are set
that are required.
The problem is, the site on which I am trying this code, does not respond.
It still waits as if the site is expecting the more data.
Here is the code snippet...
//calculate size of the request
curl_off_t size = 0;
bool chunkedTransfer = false;
for (size_t i = 0; i < numElements; i++) {
FormDataElement element = elements[i];
if (element.m_type == FormDataElement::encodedFile) {
long long fileSizeResult;
if (getFileSize(element.m_filename, fileSizeResult)) {
printf("\ngetfile size of %d\n",i);
if (fileSizeResult > maxCurlOffT) {
// File size is too big for specifying it to cURL
chunkedTransfer = true;
printf("\ninside if chunkedTransfer %d for element
%d\n",chunkedTransfer,i);
break;
}
size += fileSizeResult;
} else {
chunkedTransfer = true;
break;
}
} else
size += elements[i].m_data.size();
}
//size calculation done.
curl_easy_setopt(d->m_handle, CURLOPT_POST, TRUE);
// cURL guesses that we want chunked encoding as long as we specify the
header
if (chunkedTransfer)
*headers = curl_slist_append(*headers, "Transfer-Encoding: chunked");
else
curl_easy_setopt(d->m_handle, CURLOPT_POSTFIELDSIZE, size);
curl_easy_setopt(d->m_handle, CURLOPT_READFUNCTION, readCallback);
curl_easy_setopt(d->m_handle, CURLOPT_READFUNCTION, job);
I also checked in readCallback, it reads the give file properly and returns
the appropriated file size.
Also I checked the http traffic through Wireshark. What I observed is there
in no POST packet observed!
Please provide some solution. I wonder if there are any more parameters that
I need to set!
Received on 2008-10-04