(...) 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.


In reply to Re: download JPG series with error-handling by bart
in thread download JPG series with error-handling by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.