Hi all,
Is it possible to obtain the file size of a remote file (e.g. http://qt.nokia.com/logo.png) without downloading it? Preferably using QNetworkAccessManager.
Hi all,
Is it possible to obtain the file size of a remote file (e.g. http://qt.nokia.com/logo.png) without downloading it? Preferably using QNetworkAccessManager.
Sure. Issue a HEAD request for the file to the server. The content-length header value will be your file size.
Thanks,
I experimented a bit further and this does work for "regular" files but it doesn't work with the public link of a file on Dropbox. In that case, the header( QNetworkRequest::ContentLengthHeader) returns an empty QVariant.
Any further suggestions?
This probably means the file size is unavailable and you can't do anything about it. But before you give up check if the response you get is not a redirection, maybe the server tells you to try a different url that will return the proper size.
dirkdepauw (4th November 2010)
When the headers do not contain the file size in any form, you're out of luck.
dirkdepauw (4th November 2010)
These are the headers I get for the Dropbox file link:
ContentTypeHeader QVariant(QString, "application/xml")
ContentLengthHeader QVariant(, )
LocationHeader QVariant(, )
LastModifiedHeader QVariant(, )
CookieHeader QVariant(, )
SetCookieHeader QVariant(, )
"Server" "dbws"
"Date" "Thu, 04 Nov 2010 09:43:19 GMT"
"Content-Type" "application/xml"
"Connection" "keep-alive"
"x-robots-tag" "noindex,nofollow"
"etag" "87861968n"
"pragma" "public"
"cache-control" "max-age=0"
"Content-Encoding" "gzip"
No redirection...
As a comparison, here are the headers for http://qt.nokia.com/logo.png
ContentTypeHeader QVariant(QString, "image/png")
ContentLengthHeader QVariant(qlonglong, 1478)
LocationHeader QVariant(, )
LastModifiedHeader QVariant(QDateTime, QDateTime("wo 11. aug 09:06:42 2010") )
CookieHeader QVariant(, )
SetCookieHeader QVariant(, )
"Server" "nginx"
"Date" "Thu, 04 Nov 2010 09:46:15 GMT"
"Content-Type" "image/png"
"Connection" "keep-alive"
"Last-Modified" "Wed, 11 Aug 2010 09:06:42 GMT"
"X-Caching-Rule-Id" "downloads"
"X-Cache-Rule" "downloads"
"X-Header-Set-Id" "cache-in-proxy-24-hours"
"Cache-Control" "max-age=43200, s-maxage=43200, public"
"Content-Length" "1478"
"X-Varnish" "1135007819 1133377828"
"Age" "83560"
"Via" "1.1 varnish"
So I guess I'm out of luck!
Bookmarks