Advertisement
Combreal

uploadToImgur.cpp

May 2nd, 2021
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. /*
  2. Compile static Libcurl :
  3. cmd.exe /C "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
  4. git clone https://github.com/curl/curl.git
  5. cd curl\winbuild
  6. Set RTLIBCFG=static
  7. nmake /f Makefile.vc mode=static DEBUG=yes VC=15
  8.  
  9. Configure VS2017
  10. preprocessor macro : CURL_STATICLIB
  11. code generation : MDd
  12. include and library pathes
  13. and add the dependancies libcurl_a_debug.lib ws2_32.lib wldap32.lib crypt32.lib normaliz.lib
  14. */
  15.  
  16. #include <iostream>
  17. #include <curl\curl.h>
  18. int main()
  19. {
  20.     CURL *curl;
  21.     CURLcode res;
  22.     const char *imgPath = "C:\\Temp\\soz.jpg";
  23.     curl = curl_easy_init();
  24.     if (curl) {
  25.         curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
  26.         curl_easy_setopt(curl, CURLOPT_URL, "https://api.imgur.com/3/image");
  27.         curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  28.         curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
  29.         struct curl_slist *headers = NULL;
  30.         headers = curl_slist_append(headers, "Authorization: Client-ID imgurClientID");
  31.         curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  32.         curl_mime *mime;
  33.         curl_mimepart *part;
  34.         mime = curl_mime_init(curl);
  35.         part = curl_mime_addpart(mime);
  36.         curl_mime_name(part, "image");
  37.         curl_mime_filedata(part, imgPath);
  38.         curl_mime_type(part, "image/jpeg");
  39.         curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
  40.         res = curl_easy_perform(curl);
  41.         std::string result = curl_easy_strerror(res);
  42.         std::cout << result.c_str() << std::endl;
  43.         curl_mime_free(mime);
  44.     }
  45.     curl_easy_cleanup(curl);
  46.     system("pause");
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement