network.download bug

Hi,

I think I’ve found a bug in network.download().

Here’s what I’m trying to do: Download an image from a URL

Here’s what happens: Works perfectly the first time I download the image. Every additional time, it never gets the correct image (it still displays the original one). 

Steps:

  1. Upload an image to my server.

  2. Use network.download() to get the image (works)

  3. Change the image on my server (it still has the same URL)

  4. Relaunch the app and try downloading the image from my server again

  5. The original image is downloaded (even though it doesn’t exist on the server)

I’ve tried deleting all files in the temp directory after downloading and showing the image to the user. Finder shows that the temp directory is empty, but somehow the original image still shows up. I can never get the app to show the new image on the server. If I manually go to the URL in a browser, it *does* show the latest/correct image. It seems like the original image is still being saved/cached somewhere.

Might be useful:

I’m always saving images to the temp directory with the same name. Like I mentioned above, I empty out the temp directory after downloading/showing the image, so when I launch the app the next time and try to get the new image that’s on the server, the temp directory is empty at that point.

I have no idea how to fix this, since it seems to be some kind of behind the scenes caching that Corona does. Any help would be appreciated!

Naveen

This is caching on the device or server, so not really a bug. You can get it to ignore the cache if you add something unique to the url string every time like a timestamp. 

url = "http://www.myserver.com/image.jpg?timeStamp=".. os.time() network.download(url , "GET", networkListenerFB, "image.jpg", system.TemporaryDirectory, 0, 0)    

Thank you! Completely solved my problem. I have no experience with networking, and I probably would have spent all day trying to figure this out!

This is caching on the device or server, so not really a bug. You can get it to ignore the cache if you add something unique to the url string every time like a timestamp. 

url = "http://www.myserver.com/image.jpg?timeStamp=".. os.time() network.download(url , "GET", networkListenerFB, "image.jpg", system.TemporaryDirectory, 0, 0)    

Thank you! Completely solved my problem. I have no experience with networking, and I probably would have spent all day trying to figure this out!