cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: File uploading problem

From: Amit Nargund <amit.snargund_at_gmail.com>
Date: Tue, 7 Oct 2008 14:34:17 +0530

Hi,
I am able to POST the contents now, but rapidshare still gives me the error
saying no file selected. Does anybody knows the reason behind this? Can
anybody tell me what is missing in this for succesfully uploading a file.
Here is what I am doing,

    char *ptr=(char *)malloc(10000);
    size_t sent=d->m_formDataStream.read(ptr, 1, 10000); //reads the
contents of the file and copies it to ptr
    printf("\nsent=%d",sent);
    curl_formadd(&post, &last,
                  CURLFORM_COPYNAME, "filecontent",
                  CURLFORM_FILENAME,"u.txt",
                  CURLFORM_BUFFER, fileelement.m_filename.utf8().data(),
                  CURLFORM_BUFFERPTR, ptr,
                  CURLFORM_BUFFERLENGTH, sent,
                  CURLFORM_END);

    curl_easy_setopt(CurlHandle, CURLOPT_URL, d->m_url);
    curl_easy_setopt(CurlHandle, CURLOPT_HTTPPOST, post);
    RetVal = curl_easy_perform(CurlHandle); //perform the post
    if(RetVal)
    {
        printf("\nerror=%d!!!!\n",RetVal);
    }

Contents of the file are posted, here is what contents of the POST are.....

POST
http://rs240l3.rapidshare.com/cgi-bin/upload.cgi?rsuploadid=341846287167064448HTTP/1.1
Host: rs240l3.rapidshare.com
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 225
Expect: 100-continue
Content-Type: multipart/form-data;
boundary=----------------------------3b5f1e1890c3

------------------------------3b5f1e1890c3
Content-Disposition: form-data; name="name"; filename="u.txt"
Content-Type: text/plain

upload does work!!!!!!!!!!!!!!!!!!

------------------------------3b5f1e1890c3--

"Upload does work!!!!" is the content of the file.

On Mon, Oct 6, 2008 at 6:09 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Mon, 6 Oct 2008, Amit Nargund wrote:
>
> curl_formadd(&post, &last, CURLFORM_COPYNAME,
>> fileelement.m_filename.utf8().data(),
>> CURLFORM_FILE, file,
>>
>
> And here's the relevant quote from the fine manual:
>
> CURLFORM_FILE
> followed by a filename, makes this part a file upload part.
>
> "filename" being the keyword. You didn't provide one.
>
> Also, your "working example" showed three different parts while you only
> add one in this libcurl code.
>
> curl_easy_setopt(CurlHandle, CURLOPT_POSTFIELDSIZE, size);
>>
>
> This isn't needed and doesn't even do anything when you use
> CURLOPT_HTTPPOST.
>
> curl_easy_cleanup(CurlHandle); //free curl session
>> curl_easy_setopt(d->m_handle, CURLOPT_POST, TRUE);
>>
>
> This looks like bad copy and paste.
>
> And for more details on exactly what libcurl sends/receives, use
> CURLOPT_DEBUGFUNCTION!
>
> --
>
> / daniel.haxx.se
>
Received on 2008-10-07