### HTTP Download

Example Download Sub (Wait For)
' Download a file using resumable subs.
' Link - URL of the file to download. Backslashes are used as delimiter, to extract the local filename.
' Example: DownloadFile("http://url/filename.zip")
`Sub DownloadFile(Link As String)
Dim job As HttpJob ' Lib jHttpUtils2
Dim filename As String
' Extract filename from download link
filename = Link.SubString(Link.LastIndexOf("/") + 1)
' Init the download (get) job and start the download. Wait for the job to complete
job.Initialize("", Me)
job.Download(Link)
Wait For (job) JobDone(job As HttpJob)
' Handle job result
If job.Success Then
Try
' Create the local file using streams
Dim fout As OutputStream = File.OpenOutput(File.DirApp, filename, False)
File.Copy2(job.GetInputStream, fout)
fout.Close
Log($"Job Done. Local file created: ${filename} (${File.DirApp})"$)
Catch
' Local file can not be saved
Log($"Job Error. Can not create local file: ${filename} (${File.DirApp}) ${LastException.Message}"$)
End Try
Else
' Job error, like URL not found
Log($"Error: Download ${Link}. ${job.ErrorMessage}"$)
End If
job.Release
End Sub`

Changed: , Category: Resumable Subs, File: T6C242M1768.htm, ID: 1768