hello everyone !!
i am downloading a file using ReceiveHTTPFile , but I'd like to know how many% of the download has already been downloaded ...
how can i get a % of download from ReceiveHTTPFile ?
- skinkairewalker
- Enthusiast
- Posts: 782
- Joined: Fri Dec 04, 2015 9:26 pm
Re: how can i get a % of download from ReceiveHTTPFile ?
The manual says HTTPProgress() can be used to get the number of bytes currently transferred (see https://www.purebasic.com/documentation ... gress.html), but I don't know how to get the file size of the target file to work out the percentage of the bytes. I'm sure there'd be a tip in these forums that shows how.
Re: how can i get a % of download from ReceiveHTTPFile ?
A quick way to get file size, usually works:
Then of course, % = 100.0 * BytesDownloaded / FileSize
Code: Select all
Procedure.i HTTPFileSize(URL.s)
Protected Result.i = -1
If (URL)
Protected Raw.s = GetHTTPHeader(URL)
Protected i.i = FindString(Raw, "Content-Length: ")
Protected j.i = FindString(Raw, #CRLF$, i)
If (i And j)
Result = Val(Mid(Raw, i + Len("Content-Length: "), j - i - Len("Content-Length: ")))
EndIf
EndIf
ProcedureReturn (Result)
EndProcedure
InitNetwork()
Debug HTTPFileSize("https://www.purebasic.fr/english/styles/SkyLineBlue/imageset/purebasic_logo.png")
- skinkairewalker
- Enthusiast
- Posts: 782
- Joined: Fri Dec 04, 2015 9:26 pm
Re: how can i get a % of download from ReceiveHTTPFile ?
thanks you everyone !!
Re: how can i get a % of download from ReceiveHTTPFile ?
Good code, Kenmo.
I tried it with your avatar and it correctly returned 370 bytes:

Code: Select all
Debug HTTPFileSize("https://www.purebasic.fr/english/download/file.php?avatar=782_1286934356.png")
Re: how can i get a % of download from ReceiveHTTPFile ?
I think this info should be returned somehow by ReceiveHTTPFile() to avoid duplicate http request.
Re: how can i get a % of download from ReceiveHTTPFile ?
I fully agree - any ideas how to access the header fields of the transfer started by ReceiveHTTPFile ?djes wrote:I think this info should be returned somehow by ReceiveHTTPFile() to avoid duplicate http request.