Sub Globals
Dim Buffer(0) As byte
End Sub
Sub App_Start
URL = "http://www.b4x.com/forum/images/Basic4ppc2.gif"
DownloadFile(AppPath & "\NewImage.gif",URL)
End Sub
Sub DownloadFile (LocalFile,URL)
Response.New1
Request.New1(URL)
Response.Value = Request.GetResponse 'Launch the request and get the response.
Msgbox("Download size: " & Response.ContentLength) 'Show the file size.
Reader.New1(Response.GetStream,True) 'Use a BinaryFile object to read the data from the Response stream.
FileOpen(c1,LocalFile,cRandom)
Writer.New1(c1,False)
Dim buffer(4096) As byte
count = Reader.ReadBytes(buffer(),4096)
Do While count > 0
Writer.WriteBytes2(buffer(),0,count)
count = Reader.ReadBytes(buffer(),4096)
Loop
FileClose(c1)
Response.Close 'Close the Response stream.
Msgbox("File saved.")
End Sub