cURL / Mailing Lists / curl-library / Single Mail

curl-library

cannot open downloaded file(.jpg / mp3)?

From: skylark liu <skylark0901_at_gmail.com>
Date: Sun, 28 May 2006 07:13:28 +0800

HI:
    I use libcurl to download a file (like abc.jpg) via libcurl. But I
found the jpg file cannot be open. And the MP3 file also connot be
played. I check their file size. They differ from their original file
size. My code is as follows. Do I miss something? Thanks a lot.
*********************************************************************************************
CURL *curl_handle;
CURLcode res;

char *bodyfilename = "body.jpg";
FILE *bodyfile;
curl_global_init(CURL_GLOBAL_ALL);

/* init the curl session */
curl_handle = curl_easy_init();

/* set URL to get */
curl_easy_setopt(curl_handle, CURLOPT_URL, "http://192.168.1.9/1.jpg");

/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);

/* open the files */
bodyfile = fopen(bodyfilename,"w");
if (bodyfile == NULL) {
curl_easy_cleanup(curl_handle);
return;
}

curl_easy_setopt(curl_handle, CURLOPT_VERBOSE,1);

curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);

/* get it! */
res = curl_easy_perform(curl_handle);

fclose(bodyfile);

/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);
*********************************************************************************************
Received on 2006-05-28