I am doing a project and it's first step includes to download an image from an url and save it a some location.Further processing will be done on that image at the later stage.For this purpose I am using curl libraries in visual studio along with opencv.I am new to using curl libraries.I saw an answer here. But, I can't understand it.Here is my code
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string>
size_t write_data(void* ptr, size_t size, size_t nmemb, FILE* stream)
{
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
int main(void)
{
CURL* curl;
FILE* fp;
CURLcode res;
char* url = "http://pimg.tradeindia.com/01063301/b/1/CRO-Oscilloscope.jpg";
char outfilename[FILENAME_MAX] = "C:\\bbb.jpg";
curl = curl_easy_init();
if (curl)
{
fp = fopen(outfilename, "wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
}
return 0;
}
Thanks for the help.