How to detect/trap that image requested via display.loadRemoteImage does not exist

If the image exists on the server it’s great but when the image is not found I’d like to display a message to the user.

.isError seems to only apply if no network connection to server.

I need an “image not found” trap. [import]uid: 6547 topic_id: 21710 reply_id: 321710[/import]

Maybe you could use event.response

Ie

[code]

if event.response == nil then
print(“error”)
end [import]uid: 84637 topic_id: 21710 reply_id: 86169[/import]

The problem is that event.response is never nil.

You get back what was asked for, unfortunately.
[import]uid: 6547 topic_id: 21710 reply_id: 86173[/import]

Can you give me an example of the output of your event.response for all images?

I have an idea [import]uid: 84637 topic_id: 21710 reply_id: 86177[/import]

I have the same problem and here is my example:

Test this:

myURL = "http://thegamesdb.net/banners/boxart/original/front/9058-1.png"  
  
display.loadRemoteImage( myURL, "GET", networkListener, "helloCopy.png", system.TemporaryDirectory, 50, 50 )  

…and then test this:

[code]
myURL = “http://thegamesdb.net/banners/boxart/original/front/9058-1.jpg

display.loadRemoteImage( myURL, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, 50, 50 )
[/code] [import]uid: 24111 topic_id: 21710 reply_id: 86185[/import]

Asking for image file in the loadRemoteImage

imagefile=http://shop.rareparts.com/img/img300/10100.jpg

RESPONSE: /Users/heinz/Library/Application Support/Corona Simulator/RPwarehouse-B5DB9460E37510779FCD15DF4034D8C2/tmp/10100.jpg

Response is same whether image exists or not.
It simply has nothing to display if it doesn’t exist. [import]uid: 6547 topic_id: 21710 reply_id: 86186[/import]

Ok so here is one way that works, not the most elegant but …

[code]

local img = display.loadRemoteImage( myURL, “GET”, networkListener, “helloCopy.jpg”, system.TemporaryDirectory, 50, 50 )

if img == nil then print(“no image”) end [import]uid: 84637 topic_id: 21710 reply_id: 86194[/import]

Can’t get this code to work :confused:
It seems that it says nil even if the image works.

[code]

getImage = “http://thegamesdb.net/banners/boxart/original/front/931-1.jpg

local img = display.loadRemoteImage( getImage, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, 50, 50 )
if img == nil then
print(“no image”)
getImage = “http://thegamesdb.net/banners/boxart/original/front/931-1.jpg
display.loadRemoteImage( getImage, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, 50, 50 )
else
display.loadRemoteImage( getImage, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, 50, 50 )
end

[/code] [import]uid: 24111 topic_id: 21710 reply_id: 86197[/import]

Same. Seems img is always nil

  
 local imagefile = "http://shop.rareparts.com/img/img300/" .. partnum .. ".jpg"  
 print("imagefile=" .. imagefile)  
 local img = display.loadRemoteImage( imagefile, "GET", networkListener2, partnum .. ".jpg", system.TemporaryDirectory, 10, 170 )  
 if img == nil then  
 print("no image found")  
 else  
 imageup = true  
 end  

Forgot to mention, I’m on Build: 2011.704 since I have to be usable on < 4.3 (iPhone 3g) [import]uid: 6547 topic_id: 21710 reply_id: 86198[/import]

I dont seem to be able to edit my post:

Here is the code i meant:

getImage = "http://thegamesdb.net/banners/boxart/original/front/931-1.jpg"  
  
local img = display.loadRemoteImage( getImage, "GET", networkListener, "helloCopy.png", system.TemporaryDirectory, 50, 50 )  
if img == nil then   
 print("no image")   
 --Update on this row ;)  
 getImage = "http://thegamesdb.net/banners/boxart/original/front/931-1.png"  
 display.loadRemoteImage( getImage, "GET", networkListener, "helloCopy.png", system.TemporaryDirectory, 50, 50 )  
else  
 display.loadRemoteImage( getImage, "GET", networkListener, "helloCopy.png", system.TemporaryDirectory, 50, 50 )  
end  
  

Build 704 here too. [import]uid: 24111 topic_id: 21710 reply_id: 86199[/import]

You guys are right.

Can you please file a bug here ? http://bugs.anscamobile.com

With a test case sample code and working url (for the image) and i will get this investigated [import]uid: 84637 topic_id: 21710 reply_id: 86200[/import]

Have you tried to instead download the image first to a temp directory and then try to open it from there using newImage?

Internally loadRemoteIamge is a wrapper on Downloading the image then using loadImage, if CoronaSDK has it broken, you can do that yourself, albeit with slightly more lines of code that actually work than waiting for the bug fixes which may or may not happen. [import]uid: 3826 topic_id: 21710 reply_id: 86228[/import]

That’ll be my next attempt.

First I’m going to load a “Image not available” splash image and then I’ll go for the real thing. If none available the splash will remain. At least it’ll “look” like it’s working :slight_smile:
[import]uid: 6547 topic_id: 21710 reply_id: 86233[/import]

Got any code that works? [import]uid: 24111 topic_id: 21710 reply_id: 86297[/import]

Still working on it.

What I did for now is this:
A button that invokes a popup screen (using director)
In the popup is all the code to get the image etc.
I have text in the popup like: No image available, which gets overlaid if there is an image.
Using a touch event to dismiss the popup.

My next challenge will be to handle multiple images for a part number (auto parts ).
I plan to load them all in and them use swipe to scroll between or I might use thumbnails instead.

I’m hoping to isolate it all in the popup page so that it’s an easy toggle between text info and images for the part number. Once done I’ll be glad to share the code but since I don’t work on this full time it might take a few(?) days. [import]uid: 6547 topic_id: 21710 reply_id: 86321[/import]

Did this ever get fixed?

Did this ever get fixed?