Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
geebs
Level 7

Test if URL image exists

New at brightscript.

using this variable:
myimage = "http://192.168.1.100/images/bigimage.jpg"

i just need a way to test if the file exists or not.

something like
result = doesFileExists(myimage)

result can be boolean true/false, or better if the file exists, result holds the URL, otherwise result is null.

Any help? I'm struggling with the docs and cant find any examples. Thanks.
0 Kudos
5 REPLIES 5\
RokuMarkn
Level 8

Re: Test if URL image exists

Maybe I'm not understanding what you're trying to do, but can't you just try to download the URL? If it succeeds you'll have the contents, if the file doesn't exist you'll get a 404 error.

--Mark
0 Kudos
destruk
Level 10

Re: Test if URL image exists

yeah, you could have a script on the server to query if the file exists and return a boolean value, or use rourltransfer to check for a 200 (OK) html response, or download the file to tmp:// on the roku.
0 Kudos
geebs
Level 7

Re: Test if URL image exists

I got the intended results using rourltransfer to check for a 200 (OK) html response. and that works, however I think a better way would be to download my image to tmp:// and then test if portrait or landscape, setting X Y coords accordingly.

my way is not a pretty hack for deciding if portrait or landscape, but I understand that theres a component that can do it but only to local image files.
Even then I tried but cant find any good examples.

any good examples how to check whether a local image is portrait or landscape?
0 Kudos
TheEndless
Level 9

Re: Test if URL image exists

"geebs" wrote:
any good examples how to check whether a local image is portrait or landscape?

This assumes you're really only interested in knowing which dimension is greater, but...
Function IsLandscape(imagePath As String) As Boolean
bitmap = CreateObject("roBitmap", imagePath)
If bitmap <> invalid Then
Return bitmap.GetWidth() > bitmap.GetHeight()
End If
Return False
End Function
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
geebs
Level 7

Re: Test if URL image exists

TheEndless,
Thanks for the function. I didn't notice GetWidth() & GetHeight() was available. That'll work wonderfully.
0 Kudos