cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: FIle size

From: Richard Atterer <richard_at_2007.atterer.net>
Date: Thu, 29 Nov 2007 16:18:25 +0100

On Thu, Nov 29, 2007 at 03:56:43PM +0100, Barthold, Robert wrote:
> how can i get the file size of a file that i want to download, BEFORE i
> download the file. I didn't find any options or paramters.

You could use a HEAD request (instead of GET). The returned Content-Length
header contains the number of bytes of the file. It is not mandatory for
servers to return this header; if the server does not send it, your only
option is to download the data and count the bytes yourself.

However, a HEAD request might not be the best way if you intend to download
the file immediately after finding out the length. Instead, do a normal GET
and register a function using CURLOPT_PROGRESSFUNCTION:
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROGRESSFUNCTION

Cheers,

  Richard

-- 
  __   _
  |_) /|  Richard Atterer     |  GnuPG key: 888354F7
  | \/¯|  http://atterer.net  |  08A9 7B7D 3D13 3EF2 3D25  D157 79E6 F6DC 8883 54F7
  ¯ '` ¯
Received on 2007-11-29