cURL / Mailing Lists / curl-library / Single Mail

curl-library

Sending Large file using HTTPPOST fails with error CURLE_SEND_ERROR

From: chandrakant gupta <chandar175gupta_at_gmail.com>
Date: Thu, 9 Jul 2009 18:08:13 +0530

Hi,
Sorry for if i am posting at wrong place.

I am using HTTPPOST with Callback to post files via
HTTPS. It works great for any file up to a certain size (haven't spent
the time to narrow it down exactly). But a file of 5 mb posted
fine, and a file of 10mytes fails with error code 55
(CURLE_SEND_ERROR).

here is my code

if (m_pcurl)
    {
  struct curl_httppost* post = NULL;
  struct curl_httppost* last = NULL;
  struct curl_slist *headerlist=NULL;
  static const char buf[] = "Expect:";

  HANDLE fp = NULL ;
  if( (fp = fopen( Filepath ,"rb")) != NULL )
  {
   EC_LOG( TestMessageFile, (LPTSTR)(_T(Filepath)), result) ;
   struct _finddata_t c_file ;
      long hFind;

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

   _snprintf( Url,sizeof(Url)-1, "%s&file_size=%d", URL, c_file.size ) ;
   curl_easy_setopt(m_pcurl, CURLOPT_URL, Url);
   EC_LOG( TestMessageFile, (LPTSTR)(_T(Url)), result) ;
   curl_easy_setopt(m_pcurl, CURLOPT_PORT, ENS_COMM_PORT);
   curl_easy_setopt(m_pcurl,CURLOPT_SSL_VERIFYPEER, 0 );
   curl_easy_setopt(m_pcurl, CURLOPT_SSL_VERIFYHOST, 0);

   if( m_IsProxyEnabled != 0 )
   {
    SetOptionForProxy();
   }

   headerlist = curl_slist_append(headerlist, buf);
   curl_easy_setopt(m_pcurl, CURLOPT_HTTPHEADER, headerlist);

   CURLFORMcode result3;
   result3 = curl_formadd(&post, &last, CURLFORM_COPYNAME, "uploadedfile",
     CURLFORM_STREAM, fp,
     CURLFORM_CONTENTSLENGTH, c_file.size,
     CURLFORM_FILENAME, filename,
     //CURLFORM_CONTENTTYPE, "application/octet-stream"
     CURLFORM_END);

   curl_easy_setopt(m_pcurl, CURLOPT_READFUNCTION, read_callback);

   curl_easy_setopt(m_pcurl, CURLOPT_HTTPPOST, post);

   EC_LOG( TestMessageFile, (LPTSTR)(_T("c_file.size:")), c_file.size) ;
   EC_LOG( TestMessageFile, (LPTSTR)(_T("before easy perform")), result) ;
   result = curl_easy_perform(m_pcurl);

   EC_LOG( TestMessageFile, (LPTSTR)(_T("Upload Result:")), result) ;
   result = curl_easy_getinfo(m_pcurl, CURLINFO_HTTP_CONNECTCODE ,
&HttpConnectResponse);
   result = curl_easy_getinfo(m_pcurl, CURLINFO_RESPONSE_CODE ,
&HttpResponse);
   result = curl_easy_getinfo(m_pcurl, CURLINFO_SIZE_UPLOAD ,
&TotalUploadSize);

   EC_LOG( TestMessageFile, (LPTSTR)(_T("HttpConnectResponse:")),
HttpConnectResponse) ;
   EC_LOG( TestMessageFile, (LPTSTR)(_T("HttpResponse:")), HttpResponse) ;
   EC_LOG( TestMessageFile, (LPTSTR)(_T("TotalUploadSize:")),
TotalUploadSize) ;

   curl_slist_free_all (headerlist);
   curl_formfree(post);
   fclose((FILE*)fp);

  }

Please Help if any. what is happening is it a buffer issue or something
else.Sometime it works and sometime fails.

-- 
Regards,
Chandrakant
Received on 2009-07-09