Displaying Images Stored In Documents Dir And Temporary Dir

I need to download a group of images from an external server and display them.  I can grab the images from my server using network.download and place them into the system temporary (tmp) folder.  What I can’t seem to do is display them with display.newImage call.  Apparently, Corona executes the network.download API last.  So when display.newImage goes and looks in the tmp folder for the images, they aren’t there because Corona hasn’t downloaded them yet. 

How do I get the network.download API call to happen BEFORE . . .well . . . anything else happens.  :wink:

BTW – I also tried using display.loadRemoteImage but I don’t think that will work because I need to insert a bunch of images into a tableView. I actually got that to work but the images wouldn’t scroll with the rest of my data. 

I found a work-around. But it would be nice to know the REAL way to do it. 

Do tell, I’ve been considering the idea to add @4x images after purchase/download, so as to keep the initial download size low and better guarantee impulse sales on the App Store (research has found that people who want an app, but can’t download it due to the 50MB cellular restriction, their desire wanes or they forget/neglect to purchase it at a later time).

I created a “welcome” screen and watched terminal until my images were done downloading.  Then I moved to the screen that displays my list of images.  Not pretty, and certainly not worthy of production, but it keeps me moving forward on my project.  

So yeah, would be nice to know the proper way to do this. 

The network.download() (and all the network.* API calls for that matter) are asynchronous.  That means that they fire off an action to be completed at some point in the future and they return immediately to the calling program.   When the download finishes, a call back function that you should be passing to the call is fired off to let you know the download/request is finished and then you can load the image.

See: http://docs.coronalabs.com/daily/api/library/network/download.html

Sure, I read the API documentation.  And it looks really helpful – especially in the example code where you have:  

elseif ( event.phase == “ended” ) then
print( “displaying response image file” )
myImage = display.newImage( event.response.filename, event.response.baseDirectory, 60, 40 )
myImage.alpha = 0
transition.to( myImage, { alpha = 1.0 } )

But if I copy and paste the entire example and run it in the simulator, I get a blank screen.  In fact, I don’t event get the print statements to the terminal.  So, yeah.  It seems like I should be able accomplish what I want by using event.phase == “ended”, but it doesn’t work.  

I found a work-around. But it would be nice to know the REAL way to do it. 

Do tell, I’ve been considering the idea to add @4x images after purchase/download, so as to keep the initial download size low and better guarantee impulse sales on the App Store (research has found that people who want an app, but can’t download it due to the 50MB cellular restriction, their desire wanes or they forget/neglect to purchase it at a later time).

I created a “welcome” screen and watched terminal until my images were done downloading.  Then I moved to the screen that displays my list of images.  Not pretty, and certainly not worthy of production, but it keeps me moving forward on my project.  

So yeah, would be nice to know the proper way to do this. 

The network.download() (and all the network.* API calls for that matter) are asynchronous.  That means that they fire off an action to be completed at some point in the future and they return immediately to the calling program.   When the download finishes, a call back function that you should be passing to the call is fired off to let you know the download/request is finished and then you can load the image.

See: http://docs.coronalabs.com/daily/api/library/network/download.html

Sure, I read the API documentation.  And it looks really helpful – especially in the example code where you have:  

elseif ( event.phase == “ended” ) then
print( “displaying response image file” )
myImage = display.newImage( event.response.filename, event.response.baseDirectory, 60, 40 )
myImage.alpha = 0
transition.to( myImage, { alpha = 1.0 } )

But if I copy and paste the entire example and run it in the simulator, I get a blank screen.  In fact, I don’t event get the print statements to the terminal.  So, yeah.  It seems like I should be able accomplish what I want by using event.phase == “ended”, but it doesn’t work.