Android Question [SOLVED] HTTP Download Problem - File Not Updated

wonder

Expert
Licensed User
Longtime User
EDIT: Both DonManfred and Sorex provided viable solutions, which can be combined together.

Hello,

I want to download a small text file hosted in my server.
http://www.ninjadynamics.com/apps/hyperblox/displaydata.txt

The current file displays the following:
B4X:
1422450000000
1422453600000
100
50

I have, however, uploaded a dummy "displaydata.txt" file before, containing:
B4X:
12345
78946

Although, I've updated the file on the server via FTP, I'm still getting the dummy file values, plus an error saying the list contains only 2 elements instead of 4, as the current file does.

Here's my code:
B4X:
Sub Globals
    'Server Data
        Dim GetData, GetMOTD, GetNJAD As HttpJob  
        Private iMOTD As ImageView
        Private iNJAD As ImageView  
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If File.ExternalWritable = True AND File.Exists(File.DirDefaultExternal, "displaydata.txt") Then
        File.Delete(File.DirDefaultExternal, "displaydata.txt")
    End If
    GetData.Initialize("GetData", Me)
    GetData.Download("http://www.ninjadynamics.com/apps/hyperblox/displaydata.txt")
End Sub

Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        Select Job.Jobname
            Case "GetData"
                Dim temporary_file As OutputStream
                temporary_file = File.OpenOutput(File.DirDefaultExternal, "displaydata.txt", False)
                File.Copy2(Job.GetInputStream, temporary_file)
                temporary_file.Close          
                If File.ExternalWritable = True AND File.Exists(File.DirDefaultExternal, "displaydata.txt") Then
                    Dim server_data As List
                    server_data = File.ReadList(File.DirDefaultExternal, "displaydata.txt")
                    MOTD_ExpireDate = server_data.Get(0)
                    NJAD_ExpireDate = server_data.Get(1)
                    MOTD_ChanceRate = server_data.Get(2)
                    NJAD_ChanceRate = server_data.Get(4)
                    If MOTD_ExpireDate <> 0 Then AND DateTime.Now < MOTD_ExpireDate Then
                            GetMOTD.Initialize("GetMOTD", Me)
                            GetMOTD.Download("http://www.ninjadynamics.com/apps/hyperblox/motd.png")
                    End If
                    If NJAD_ExpireDate <> 0 Then AND DateTime.Now < NJAD_ExpireDate Then
                            GetNJAD.Initialize("GetNJAD", Me)
                            GetNJAD.Download("http://www.ninjadynamics.com/apps/hyperblox/njad.png")
                    End If              
                End If
          
            Case "GetMOTD"
                iMOTD.Bitmap = Job.GetBitmap
                iMOTD.BringToFront
          
            Case "GetNJAD"
                iNJAD.Bitmap = Job.GetBitmap
                iNJAD.BringToFront
          
        End Select
    Else
    End If
End Sub

Is there anything wrong? Should I flush my HTTP cache? If so, how?
I have already restarted the tablet and deleted the local displaydata.txt file manually.
 
Last edited:
  • Like
Reactions: eps

sorex

Expert
Licensed User
Longtime User
try with

B4X:
GetData.Download("http://www.ninjadynamics.com/apps/hyperblox/displaydata.txt?r="&datetime.now)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
remove the dim for the httpjobs from globals.
Put a
B4X:
Dim job As httpjob
whenever you want to start a new job
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If File.ExternalWritable = True AND File.Exists(File.DirDefaultExternal, "displaydata.txt") Then
        File.Delete(File.DirDefaultExternal, "displaydata.txt")
    End If
    Dim GetData as Httpjob
    GetData.Initialize("GetData", Me)  
    GetData.Download("http://www.ninjadynamics.com/apps/hyperblox/displaydata.txt")
End Sub
Do the same for GetMOTD and GetNJAD (put the dim in the sub where you start the job
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
try with

B4X:
GetData.Download("http://www.ninjadynamics.com/apps/hyperblox/displaydata.txt?r="&datetime.now)
Thanks for the suggestions, Sorex, but I don't think that's what I'm looking for...

remove the dim for the httpjobs from globals.
Put a
B4X:
Dim job As httpjob
whenever you want to start a new job
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If File.ExternalWritable = True AND File.Exists(File.DirDefaultExternal, "displaydata.txt") Then
        File.Delete(File.DirDefaultExternal, "displaydata.txt")
    End If
    Dim GetData as Httpjob
    GetData.Initialize("GetData", Me)
    GetData.Download("http://www.ninjadynamics.com/apps/hyperblox/displaydata.txt")
End Sub
Do the same for GetMOTD and GetNJAD (put the dim in the sub where you start the job
Thank you for your reply! I will try that solution and post the result here later.

EDIT: Thank you very much, DonManfred!!! It worked!! :D I love this community!!
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
Thanks for the suggestions, Sorex, but I don't think that's what I'm looking for...

Did you even try it? :)

I wrote a test and the behaviour is as you described when changing the file and downloading it again during the active app run.

adding the mod solves it here as it bypasses cached results as the url is different than the one(s) before.
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Did you even try it? :)

I wrote a test and the behaviour is as you described when changing the file and downloading it again during the active app run.

adding the mod solves it here as it bypasses cached results as the url is different than the one(s) before.
Does the <r=datetime.now> forces the most recent version to be downloaded? If so, I will implement it as well, just to be safe.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Upvote 0
Top