How to download a file and save it

halo

Member
Licensed User
Hi
Sorry about my broken english.
The main reason why I bought Basic4PPC is,every day I want to download a file from the internet and save it on my HTC Touch Diamond.

To get startet with basic4ppc I need your :sign0085:
I think I have to use the HTTP library.

For example I want to download this file:
http://www.b4x.com/files/SpriteExample.zip

Could you please give me an example for downloading this file.

Best regards
Halo :sign0104:
 

Mr_Gee

Active Member
Licensed User
Longtime User
Welcome to B4PPC and the forum...

As for your request, have you seen the help files?
if you look at this page (and scroll down a bit)
you will see the download sub
HTTP
 

halo

Member
Licensed User
Ok
Thank you Mr_Gee
With this code I can download the File:
B4X:
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

I did not understand very much of this code, but it runs.
I saw this example bevor. But I have very much problems with understanding wich object i have to add. Sorry for my dopyness.

Thank you very much for your help.

Greets Halo
 

Mr_Gee

Active Member
Licensed User
Longtime User
yes thats the one..

I understand it can be a bit overwhelming at first, but when you are working with the application for a while you will get accustomed to it...

my advise start with the tutorials, the are really good
 
Top