Check if "the URL" returns an image file?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
makeshyft
Posts: 222
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Check if "the URL" returns an image file?

Post by makeshyft » Mon May 20, 2013 5:23 am

How would I go about doing a check whether HTTP link is returning an image file or a 404 page?

I'm worried that not all servers report 404 the same way, so a faulty image link would return a whole 404 page with HTML and etc.

THe HTTP links are intended to point only to an image files recognizable by Livecode.

Any help would be appriciated.....Thank you livecoders.
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Check if "the URL" returns an image file?

Post by Simon » Mon May 20, 2013 5:58 am

404 pages contain <html></html> an image wouldn't.
But more: .png have PNG in the first line of the data, jpg have JFIF and bmp's have BM. Not sure if those are constants.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Check if "the URL" returns an image file?

Post by BvG » Mon May 20, 2013 10:35 am

It'd be worthwhile to check the libURLLastRHHeaders() function. A 404 is required to have a not found response at the start of the headers if I remember the specification correctly.

For example, my server returns the following on the first line, first 404 then "regular":

Code: Select all

HTTP/1.1 404 Not Found

Code: Select all

HTTP/1.1 200 OK
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

makeshyft
Posts: 222
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Check if "the URL" returns an image file?

Post by makeshyft » Mon May 20, 2013 4:40 pm

Between the both suggestions, I'll be able to make it work. Thank you! Will return to tag subject as solved.
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

makeshyft
Posts: 222
Joined: Mon Apr 15, 2013 4:41 am
Contact:

[solved] Re: Check if "the URL" returns an image file?

Post by makeshyft » Thu May 23, 2013 10:49 pm

Works like a charm:

Code: Select all

 read from file ImageURL for 1 line
   put it into myfilechunk // check file headers
   if it contains "jfif" then answer "JPEG"
   else if it contains "exif" then answer "JPEG with exif"
   else if it contains "BM" then answer "BMP"
   else if it contains "PNG" then answer "PNG"
   else if it contains "GIF" then answer "GIF"
   else 
   end if
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

Post Reply