cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: file upload

From: chandrakant gupta <chandar175gupta_at_gmail.com>
Date: Mon, 22 Jun 2009 10:39:04 +0530

Hi,
Here is my code ,
I am using chunk only,
 CURL *curl;
    CURLcode result;
 static const char buf[] = "Expect:";
 static const char buf1[] = "Transfer-Encoding: chunked";
 static const char buf2[]= "Content-Disposition: form-data;
uploadedfile=Readme.txt;name=Readme.txt";

 struct curl_slist *headerlist=NULL;

 curl = curl_easy_init();
 if (curl)
    {

  curl_easy_setopt(curl, CURLOPT_URL, "
http://192.168.100.40//3108//ch_handoutadd.php?id=ABCDEFG&connectedToJava=YES
");
 // curl_easy_setopt(curl, CURLOPT_URL, "
http://192.168.100.40//teradocs//ABCDEFG//Handouts//");
  curl_easy_setopt(curl, CURLOPT_PORT, 80);
  curl_easy_setopt(curl, CURLOPT_VERBOSE ,1);

  HANDLE fp = NULL ;

  if( (fp = fopen( Filepath ,"rb")) != NULL )
  {
   struct _finddata_t c_file ;
      long hFind;
//
      printf ("Target file is %s.\n", Filepath);

   if( (hFind = _findfirst( Filepath, &c_file )) != -1L )
   {

    Filebuf = new char[c_file.size ];
      printf ("The file size found is %d\n", c_file.size);

   }

   headerlist = curl_slist_append(headerlist, buf);
   headerlist = curl_slist_append(headerlist, buf1);
   headerlist = curl_slist_append(headerlist, buf2);

   curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
    curl_easy_setopt(curl, CURLOPT_READDATA ,fp );
    curl_easy_setopt(curl, CURLOPT_READFUNCTION ,read_callback );

    curl_easy_setopt(curl, CURLOPT_POST, 1);
   result = curl_easy_perform(curl);

now here also my read function is getting called and it is reading full file
but the file is not getting upload please help. and i have to pass two
parameter to Php page can i pass this way See buf2.

On 6/22/09, Daniel Stenberg <daniel_at_haxx.se> wrote:
>
> On Fri, 19 Jun 2009, chandrakant gupta wrote:
>
> I am uploading file using CURLOPT_POST but my fine is not getting uploaded.
>> plaese help.
>>
>> curl_easy_setopt(curl, CURLOPT_URL, "
>> http://192.168.100.40//3108//ch_handoutadd.php");
>> curl_easy_setopt(curl, CURLOPT_PORT, 80);
>> curl_easy_setopt(curl, CURLOPT_VERBOSE ,1);
>>
>> result = curl_easy_setopt(curl, CURLOPT_POSTFIELDS
>>
>> ,"file=winzip100.exe&id=AA48AT5R&connectedToJava=YES&uploadedfile=winzip100.exe&name=winzip100.exe");
>> curl_easy_setopt(curl, CURLOPT_POST, 1);
>> result = curl_easy_perform(curl);
>>
>> at server page is getting called but the file is not uploadded.
>>
>
> That's not a file upload, that's a chunk of data sent in a POST. You
> probably want curl_formadd() and friends.
>
> --
>
> / daniel.haxx.se
>

-- 
Regards,
Chandrakant
TERA INFORMATICS PVT LTD
Received on 2009-06-22