Get a download file size before download (gb.net.curl)
Posted
#1
(In Topic #569)
Guru

I'm downloading an archive using the gb.net.curl HttpClient object
Like the code below…
Code (gambas)
In the _Read() event i can get the download size but i can't find a way to get the file size before downloading.
I tried the HttpClient.Head() method but the list of headers did not have Content.Length ?
A bit puzzled.
And help appreciated
Bruce
Posted
Guru

<IMG src="https://www.cogier.com/gambas/curldownload.png">
</IMG>
Posted
Guru

cogier said
I have tried a few things, but I can't get the result you are looking for. If it helps there is a 'Size' property in 'Download' but I can't get it to work.
<IMG src="https://www.cogier.com/gambas/curldownload.png"></IMG>
Thanks Charlie.
I'd suspect that Size property is just downloaded not total size.
Puzzling.
Posted
Enthusiast

Code
Use the -I option to only retrieve the headers, and look for the “Content-Length” header. Add the -L option if necessary to follow redirects. For example:
$ curl -L -I https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso
HTTP/1.1 302 Found
Date: Mon, 18 Jun 2018 09:51:32 GMT
Server: Apache/2.4.29 (Unix)
Location: https://gensho.ftp.acc.umu.se/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso
Cache-Control: max-age=300
Expires: Mon, 18 Jun 2018 09:56:32 GMT
Content-Type: text/html; charset=iso-8859-1
HTTP/1.1 200 OK
Date: Mon, 18 Jun 2018 09:51:32 GMT
Server: Apache/2.4.29 (Unix)
Last-Modified: Sat, 10 Mar 2018 11:56:52 GMT
Accept-Ranges: bytes
Content-Length: 305135616
Age: 228
Content-Type: application/x-iso9660-image
may it helps …
Posted
Guru

PJBlack said
found thisCode
Use the -I option to only retrieve the headers, and look for the “Content-Length” header. Add the -L option if necessary to follow redirects. For example:
$ curl -L -I https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso
HTTP/1.1 302 Found
Date: Mon, 18 Jun 2018 09:51:32 GMT
Server: Apache/2.4.29 (Unix)
Location: https://gensho.ftp.acc.umu.se/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso
Cache-Control: max-age=300
Expires: Mon, 18 Jun 2018 09:56:32 GMT
Content-Type: text/html; charset=iso-8859-1
HTTP/1.1 200 OK
Date: Mon, 18 Jun 2018 09:51:32 GMT
Server: Apache/2.4.29 (Unix)
Last-Modified: Sat, 10 Mar 2018 11:56:52 GMT
Accept-Ranges: bytes
Content-Length: 305135616
Age: 228
Content-Type: application/x-iso9660-image
may it helps …
It help yes but not as i'd hoped.
using curl -I i read the headers for the file in question (the gambas source archive)
https://gitlab.com/gambas/gambas/-/archive/master/gambas-master.zip
the header list i got was something i had also managed to view using httpclient but did not see any content-length info.
and Benoit says this on the M/l..
Benoit said
Content-Length is not a mandatory header. So if it is not present, you
can't know by advance the size of the download.
so looks to me like the file i am trying to get the size of is one of those that does not report it
Sigh , oh well.
Thanks for the help guys
Bruce
Posted
Guru

Just an observation.
Line 8 on my first post does not show as i wrote it.
written it is just
Dim sZip As String = "the/url/to/fie"
the post shows href= and class= stuff that should not be there.
Just a note m8. dunno if it anything to do with you or not.
Bruce.
Posted
Guru

Posted
Guru

Posted
Guru

<IMG src="https://www.cogier.com/gambas/URL%20Issue.png">
</IMG>
Posted
Guru

cogier said
Ahh yes, we have run into this before. I have corrected your first post. You need to add this: -
<IMG src="https://www.cogier.com/gambas/URL%20Issue.png"></IMG>
aah thanks m8, will remember that in future
1 guest and 0 members have just viewed this.



