Page 1 of 1
Check if "the URL" returns an image file?
Posted: Mon May 20, 2013 5:23 am
by makeshyft
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.
Re: Check if "the URL" returns an image file?
Posted: Mon May 20, 2013 5:58 am
by Simon
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
Re: Check if "the URL" returns an image file?
Posted: Mon May 20, 2013 10:35 am
by BvG
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":
Check if "the URL" returns an image file?
Posted: Mon May 20, 2013 4:40 pm
by makeshyft
Between the both suggestions, I'll be able to make it work. Thank you! Will return to tag subject as solved.
[solved] Re: Check if "the URL" returns an image file?
Posted: Thu May 23, 2013 10:49 pm
by makeshyft
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