Get a download file size before download (gb.net.curl)
Posted: Monday 1st February 2021 2:39pm
Hi all
I'm downloading an archive using the gb.net.curl HttpClient object
Like the code below...
I tried the HttpClient.Head() method but the list of headers did not have Content.Length ?
A bit puzzled.
And help appreciated
Bruce
I'm downloading an archive using the gb.net.curl HttpClient object
Like the code below...
Public hClient As HttpClient
Public hFile As File
Public Sub GetArchive()
Dim sFork As String = "gambas"
Dim sName As String = "gambas-stable.zip"
Dim sZip As String = "https://gitlab.com/gambas/gambas/-/archive/stable" &/ sName
If Message.Question("Download archive?", "Yes", "No") <> 1 Then Return
FMain.MeEnabled(False)
hClient = New HttpClient As "hClient"
hClient.Timeout = 20
hClient.URL = sZip
hFile = Open Parent &/ File.Name(sZip) For Write Create
hClient.Get()
End
Public Sub hClient_Read()
Dim sSize As String, Data As Variant
Dim sTemp As String[]
Read #hClient, Data, -256
Dim iGot As Integer = hClient.Downloaded
If iGot < 1024 Then
sSize = Str(iGot) & " Bytes"
Else If iGot < (1024 * 1024) Then
sSize = Str(iGot / 1024)
If InStr(sSize, ".") Then sSize = sSize[0, InStr(sSize, ".") + 2]
sSize &= " Kilobytes"
Else
sSize = Str(iGot / (1024 * 1024))
If InStr(sSize, ".") Then sSize = sSize[0, InStr(sSize, ".") + 2]
sSize &= " Megabytes"
Endif
Print "Downloading: " & sSize & "\r"
Write #hFile, Data
End
Public Sub hClient_Finished()
Wait 0.1
If hClient Then hClient.Close()
If hFile Then hFile.Close()
Print ("\nDownload Complete.\n")
Wait 0.1
FMain.MeEnabled(True)
FMain.tvComp.Input("cd '" & Parent & "' && unzip -ou " & File.Name(hClient.URL) & "\n")
End
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