Dear Monks,

I am working on a system with a large number of JPEG images stored online (and accessible only via HTTP - no local access). Images change frequently, and appear and disappear very regularly.

I would like to catalogue the various makes and models of cameras used to create these images, and report on various other stats relating to the metadata.

I've got something working now which downloads the images, uses Image::ExifTool to get at the metadata and all works - brilliant!

However, trawling through these images is a massive drain on bandwidth (as I'm downloading the entire image for every image) and as I'm contracting and working from home I'm starting to hit my bandwidth allowance and need to streamline my downloading.

I've got a new script working locally on a cache of images that only needs the first few bytes (enough to grab the portion of the file contain the EXIF metadata) of the file in order for me to get at the data I want. This works fine and will be a massive saving on network bandwidth when the images can be several megs and I only need 1K at most.

So, now is the time to make my new script work over the network but I'm stuck......how do I download just the first 1K (or whatever) of a file over HTTP? Can I do this with the LWP packages or should I be making raw TCP connections and simply closing the socket when I have enough data?

Your advice would be greatly appreciated!!!!


In reply to How to download JUST the first X bytes of HTTP response ? 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.