PDA

View Full Version : Download file from X to Y bytes



mecrazycoder
11th May 2011, 09:19
I have couple of doubts regarding downloading of file using QT

1. Is it possible to get the size of file before start downloading ?
2. Also is it possible to download only x to y bytes from a file ?

Thanks in advance.

wysota
11th May 2011, 12:57
It depends if the server you are downloading from (assuming you want to use HTTP) supports such operations. There is nothing preventing you from issuing the right commands in the Qt client. The server may simply not understand them or decline to use them.

ChrisW67
11th May 2011, 23:24
Assuming HTTP/HTTPS:
1. Issue a HEAD request and look at the Content-Length: header
2. If the HEAD request headers contains the "Accept-Ranges: bytes" header then you might be able to GET a specified range of bytes with the "Range: bytes=500-999" (e.g. second 500 bytes) header.

rsilva
11th May 2011, 23:48
ChrisW67, I want to do some download things like this, Qt have specific functions for this GET with range? Or we need to build the request and send ?

ChrisW67
12th May 2011, 05:22
You have to set the request headers yourself and then use the QNetworkAccessManager to send the request