cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Binary data

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 27 Mar 2003 15:31:34 +0100 (CET)

On Thu, 27 Mar 2003, Sigal Algranaty wrote:

> Sorry if this question is for something that appears in documentation.
>
> How can I get binary data from url?

libcurl downloads everything binary by default.

> If I have a url which is an image, for example, and I want it to be
> downloaded to an image file on my disc, how do I do it?

Something like this (untested code) might work:

int main(void)
{
  CURL *curl;
  CURLcode res;
  FILE *storehere;

  storehere=fopen("dumpit", "wb"); /* b for windows people */

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://imagesite.com/image.png");

    curl_easy_setopt(curl, CURLOPT_WRITEDATA, storehere); /* write here */

    /* If you use windows and libcurl as a DLL, you must also set a callback
       function with CURLOPT_WRITEFUNCTION */

    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This SF.net email is sponsored by:
The Definitive IT and Networking Event. Be There!
NetWorld+Interop Las Vegas 2003 -- Register today!
http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
Received on 2003-03-27