Android Question File download from web problems

jpvniekerk

Active Member
Licensed User
Longtime User
It seems I am not getting the latest file to download from the web.

I use B4A 6.00 and Library OkHttpUtils2 (version 2.2)

Code (extracted) is:
B4X:
Sub Globals
    ...
    Private job1 As HttpJob
    ...
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ...
    job1.Initialize("job1",Me)
    job1.Download("http://www.{my url}/testfile.csv")
    ...
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
            Select Job.JobName
                Case "job1"
                    Dim out As OutputStream
                    File.Delete(File.DirDefaultExternal,"testfile.csv")
                    out = File.OpenOutput(File.DirDefaultExternal,"testfile.csv",True)
                    File.Copy2(Job.GetInputStream, out)
                    out.Close
            End Select
        Else
            Log("Error: " & Job.ErrorMessage)
            Job.Release
            Return
    End If
    Job.Release
       ' some code here to read the csv file and create a map...
End Sub

If I change the contents of testfile.csv and upload it, overwriting the old one, the code runs fine, but when I open testfile.csv on the device, it is still the old contents.
If I reboot the device and do it again, the correct file is downloaded.
It seems that the file is downloaded from cache and not directly from the web.
How can I force the file to NOT use the cache, and always download from the web?

Thanks for any help!
 
Last edited:

fixit30

Active Member
Licensed User
Longtime User
You need to trick the server to send you the current file, the easiest way is to send a fake parameter to the server with your request.

Something like:

B4X:
job1.Download2("http://www.{my url}/testfile.csv", Array as String("q", DateTime.Now))
 
Upvote 0
Top