Page 1 of 1
how can i get a % of download from ReceiveHTTPFile ?
Posted: Sun Mar 10, 2019 1:57 am
by skinkairewalker
hello everyone !!
i am downloading a file using ReceiveHTTPFile , but I'd like to know how many% of the download has already been downloaded ...
Re: how can i get a % of download from ReceiveHTTPFile ?
Posted: Sun Mar 10, 2019 2:12 am
by Dude
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 ?
Posted: Sun Mar 10, 2019 3:24 am
by kenmo
A quick way to get file size, usually works:
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")
Then of course, % = 100.0 * BytesDownloaded / FileSize
Re: how can i get a % of download from ReceiveHTTPFile ?
Posted: Sun Mar 10, 2019 4:46 am
by skinkairewalker
thanks you everyone !!
Re: how can i get a % of download from ReceiveHTTPFile ?
Posted: Sun Mar 10, 2019 5:17 am
by Dude
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 ?
Posted: Thu Jul 18, 2019 8:02 pm
by djes
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 ?
Posted: Fri Mar 27, 2020 1:12 am
by nalor
djes wrote:I think this info should be returned somehow by ReceiveHTTPFile() to avoid duplicate http request.
I fully agree - any ideas how to access the header fields of the transfer started by ReceiveHTTPFile ?