I am trying to request and display graphics dynamically in my app using the following code
for i=1, #Thumbnail
do
local imagePath = system.pathForFile(i..".jpg", system.TemporaryDirectory)
local myFile = io.open(imagePath, "wb")
http.request{ url = Thumbnail[i], sink = ltn12.sink.file(myFile),}
display.newImage(i..".jpg", system.TemporaryDirectory, 0, i \* 50);
end
Thumbnail is a table and each entry contains a valid url to an image. Not sure if the file size is a factor, but the images I am trying to retrieve are all 8k. The issue that I am experiencing is that only the last file in the loop is getting saved properly.
For example if I have total 3 images I want to download and display if I navigate to the system.TemporaryDirectory location in a finder window I can see that my app downloads and creates 3 files called 1.jpg, 2.jpg, 3.jpg however 1 and 2 are corrupt and the size is only 4k where the third file 3.jpg is 8k. Why is that?
The same problem exists if I increase or decrease the number of images I am trying to download, it is only the last image that is created properly.
I’m a beginner to lua and corona and am not sure what I am doing wrong. Can someone please help.
Thanks
Joe [import]uid: 5963 topic_id: 5644 reply_id: 305644[/import]