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.
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
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!you can download the file, or you can get the data from the page using okhttp
[B4X] OkHttpUtils2 with Wait For
Downloading resources is simpler with the new Resumable Subs feature. Using Wait For we can wait for the JobDone event in the same sub that started the download. No longer is it needed to have a single sub that handles all requests results. Simplest example: Dim j As HttpJob j.Initialize(""...www.b4x.com
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
Tha
THanks i will try it out later!
It works beautifully.here's the sample source code
remembering that I accessed raw, to get the file link.
View attachment 89306
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
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):can you send which is the github directory you want to get the files from?
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):
COVID-19/csse_covid_19_data/csse_covid_19_daily_reports at master Β· CSSEGISandData/COVID-19
Novel Coronavirus (COVID-19) Cases, provided by JHU CSSE - COVID-19/csse_covid_19_data/csse_covid_19_daily_reports at master Β· CSSEGISandData/COVID-19github.com
OOOOOO OK! thanks i didn't thought to have a variable link!! Thanks for you help and precious tips!!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.