in reply to download JPG series with error-handling

(...) but in reality it's grabbing the 404 message from the website.

My question is, what's the easiest way to check for the case when the URL "www.website.com/42/1.jpg" is sending back an HTML "sorry" page, not a JPG?

I'm just using LWP::Simple at the moment with getstore().
No, that's not correct. LWP::Simple's getstore will not save a file if the status code is not 200 OK.

Just check the return value of getstore(), it'll simply tell you whether the fetch has failed, or whether it saved anything:

    getstore($url, $file)
       Gets a document identified by a URL and stores it in the file. The
       return value is the HTTP response code.
Just check if its return value is equal to 200.

If the files did indeed get saved and they're HTML pages with error messages, then the webserver is misbehaving, and it returned a "200 OK" status message regardless. No other way of checking the webserver's status you can think of, would make a difference.

You can still snoop the saved file, for example using the command line utility file on Unixy systems — perhaps Cygwin has it ported to Windows.

If this is for Windows, and you can't find file, but you do have ImageMagick installed, then its command line utility identify can recognize whether you do have valid JPEG files.

  • Comment on Re: download JPG series with error-handling

Replies are listed 'Best First'.
Re^2: download JPG series with error-handling
by data64 (Chaplain) on Mar 29, 2005 at 10:35 UTC

    Perl implementation of the file utility available from the Perl Power Tools project.