Results 1 to 6 of 6

Thread: File size of a remote file without downloading it

  1. #1
    Join Date
    Jan 2006
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default File size of a remote file without downloading it

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: File size of a remote file without downloading it

    Sure. Issue a HEAD request for the file to the server. The content-length header value will be your file size.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: File size of a remote file without downloading it

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: File size of a remote file without downloading it

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    dirkdepauw (4th November 2010)

  6. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: File size of a remote file without downloading it

    When the headers do not contain the file size in any form, you're out of luck.

  7. The following user says thank you to tbscope for this useful post:

    dirkdepauw (4th November 2010)

  8. #6
    Join Date
    Jan 2006
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: File size of a remote file without downloading it

    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!

Similar Threads

  1. Max size of image file
    By Astrologer in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2010, 14:39
  2. How to get File version size?
    By phillip_Qt in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 07:53
  3. QFtp: downloading a whole folder from a remote server.
    By balazsbela in forum Qt Programming
    Replies: 5
    Last Post: 5th August 2007, 10:34
  4. Replies: 3
    Last Post: 25th May 2007, 08:49
  5. Remote file list Drop to desktop
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 10th February 2007, 00:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.