c++ - libcurl not uploading the entier file -


i'm trying upload file http server. i'm getting 200 ok server, code below transmitting 4 bytes.

size_t myclass::read_callback(void *ptr, size_t size, size_t nmemb, void *userp) {     handler->read(buffer, buffer_size);   // buffer_size 100000      size_t res = handler->gcount();     if( res == 0 )         return 0;      ptr = buffer;   // buffer array of char, defined in myclass     size = res;     nmemb = sizeof(char);      return 1; }   void myclass::upload_function(const std::string& url) {     curl *curl;     curlcode res;      std::ifstream if_file;     if_file.open("/path_to_file", std::ios::binary);     handler = &if_file;   // handler defined in myclass      /* in windows, init winsock stuff */     res = curl_global_init(curl_global_default);     /* check errors */     if(res != curle_ok) {         // failure         return;     }           curl = curl_easy_init();     if(curl) {         curl_easy_setopt(curl, curlopt_url, "hostname");         curl_easy_setopt(curl, curlopt_post, 1l);         curl_easy_setopt(curl, curlopt_readfunction, myclass::read_callback);         curl_easy_setopt(curl, curlopt_verbose, 1l);          struct curl_slist *chunk = null;         chunk = curl_slist_append(chunk, "transfer-encoding: chunked");         chunk = curl_slist_append(chunk, "content-type: application/x-mpegurl");         res = curl_easy_setopt(curl, curlopt_httpheader, chunk);          /* perform request, res return code */         res = curl_easy_perform(curl);         /* check errors */         if(res != curle_ok) {             // failed         }         else          {             double speed_upload, total_time;             curl_easy_getinfo(curl, curlinfo_speed_upload, &speed_upload);             curl_easy_getinfo(curl, curlinfo_total_time, &total_time);              fprintf(stderr, "speed: %0.3f b/sec during %.3f seconds\n",               speed_upload, total_time);         }         /* cleanup */         curl_easy_cleanup(curl);             }     curl_global_cleanup();     if_file.close();  } 

the callback doesn't seem copy data buffer. assigns local pointer, quite without effect.

the callback looks c++ method can't used callback in c api doesn't know c++ objects...


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -