Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. static size_t reader(void *ptr, size_t size, size_t nmemb, FILE *stream) {
  2. size_t retcode = fread(ptr, size, nmemb, stream);
  3. cout << "*** We read " << retcode << " bytes from file" << endl;
  4. return retcode;
  5. }
  6.  
  7. void upload() { //upload() is called from ouside
  8. FILE *pFile;
  9. pFile = fopen("map.txt" , "r");
  10.  
  11. struct stat file_info;
  12. stat("map.txt", &file_info);
  13. size_t size = (size_t)file_info.st_size;
  14. uploadFile(pFile, size);
  15. }
  16.  
  17. bool uploadFile(void* data, size_t datasize) {
  18. CURL *curl;
  19. CURLcode res;
  20.  
  21. curl = curl_easy_init();
  22. if (curl) {
  23. char *post_params = ...;
  24. curl_easy_setopt(curl, CURLOPT_URL, url);
  25. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
  26. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_params);
  27. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(post_params));
  28. curl_easy_setopt(curl, CURLOPT_READFUNCTION, reader);
  29. curl_easy_setopt(curl, CURLOPT_READDATA, data);
  30. curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) datasize);
  31.  
  32. res = curl_easy_perform(curl);
  33. curl_easy_cleanup(curl);
  34. }
  35. return true;
  36. }
  37.  
  38. *** We read 490 bytes from file
  39. *** We read 0 bytes from file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement