Android Question How to refresh downloaded file in Dirinternal?

GERSON PINTO

Member
Licensed User
Hello!
My app downloads and saves the file in the dirinternal folder.
I'm using OKHttputils2, however when I change the file on the server, the application continues to display the old file.

What is the solution for forcing the old file to be replaced with new one?

The application downloads the file each time it is started
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Without seeing your code, I'd say:

1) Download the new file with a temp name (in case the download isn't successful & you need to continue using the old one)
2) Delete the old file (File.Delete)
3) Copy the new (temp) file to the old file name (File.Copy - there's no File.Move function in B4A)
4) Delete the new (temp) file (File.Delete)
5) Reload the file in your app

- Colin.
 
Upvote 0

emexes

Expert
Licensed User
Is the server local and under your control, or a third-party host that you access via eg FTP?

If you access the file from another computer/browser, do you get the old or new version of the file?

Your symptoms match a problem I have with a third-party host, which is that html files are served with a long-ish expiry time, and some intermediate proxy/cache on the journey through the internet continues to serve the not-yet-expired version of the file, rather than the new version.
 
Upvote 0

GERSON PINTO

Member
Licensed User
Thank you guys!
Yes emexes,I am using third-party host but I think that the Computermith64's solution will solve the problem. I found here the code that works fine:

B4X:
Dim FilesToDelete As List

    FilesToDelete.Initialize
    FilesToDelete.AddAll(File.ListFiles(File.DirInternal))

    For I = 0 To FilesToDelete.Size -1
        File.Delete(File.DirInternal, FilesToDelete.Get(I))

    Next
 
Upvote 0
Top