Android Question Download file from GitHub repository

Mike1970

Well-Known Member
Licensed User
Hi everyone.
I never used github but now I need to download a file from a repository.
I have a repository , and I want to download only the latest added file.
It’s possibile to do this in b4x?
Thanks in advance.
 

Lucas Siqueira

Active Member
Licensed User
Hi everyone.
I never used github but now I need to download a file from a repository.
I have a repository , and I want to download only the latest added file.
It’s possibile to do this in b4x?
Thanks in advance.
you can download the file, or you can get the data from the page using okhttp



B4X:
Sub DownloadAndSaveFile (Link As String)
   Dim j As HttpJob
   j.Initialize("", Me)
   j.Download(Link)
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
       Dim out As OutputStream = File.OpenOutput(File.DirInternal, "filename.dat", False)
     File.Copy2(job.GetInputStream, out)
     out.Close '<------ very important
   End If
   j.Release
End Sub

B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
End If
j.Release
 

Mike1970

Well-Known Member
Licensed User
Tha
you can download the file, or you can get the data from the page using okhttp



B4X:
Sub DownloadAndSaveFile (Link As String)
   Dim j As HttpJob
   j.Initialize("", Me)
   j.Download(Link)
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
       Dim out As OutputStream = File.OpenOutput(File.DirInternal, "filename.dat", False)
     File.Copy2(job.GetInputStream, out)
     out.Close '<------ very important
   End If
   j.Release
End Sub

B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
End If
j.Release
THanks i will try it out later!
 

Lucas Siqueira

Active Member
Licensed User

Attachments

Last edited:

Lucas Siqueira

Active Member
Licensed User
It works beautifully.
but it works only to ONE file.

unfortunately the repository I have to use updates once a day with a NEW file, not updating the previous.

so I need to get the last file and then read it
can you send which is the github directory you want to get the files from?
 

Lucas Siqueira

Active Member
Licensed User
Oh i noticed that for the same datas there is the time-series version (that I can use with your example), and daily-report (that is what I was talking about):

apparently it is simple to solve your case, the published file always has the same name ... month-day-year ...
so I got the base of the link: https://raw.githubusercontent.com/C...se_covid_19_data/csse_covid_19_daily_reports/

and add in it the name of the file formed by the month-day-year.csv
that way you will always download the file of the day, updated!

I try to download the file of the current date, if it does not exist, the app tries to download the one from the previous day, if it does not exist the app will try until the previous 5 days.
 

Attachments

Mike1970

Well-Known Member
Licensed User
apparently it is simple to solve your case, the published file always has the same name ... month-day-year ...
so I got the base of the link: https://raw.githubusercontent.com/C...se_covid_19_data/csse_covid_19_daily_reports/

and add in it the name of the file formed by the month-day-year.csv
that way you will always download the file of the day, updated!

I try to download the file of the current date, if it does not exist, the app tries to download the one from the previous day, if it does not exist the app will try until the previous 5 days.
OOOOOO OK! thanks i didn't thought to have a variable link!! Thanks for you help and precious tips!!
 
Top