Good morning,

I post this at the risk of sounding repetitive, but I am truly baffled at this problem. I posted the original problem in this node, and have come a little ways since then, but not much. I admit I am somewhat out of my league here - I'm not terribly familiar with how HTTP headers work, which could explain most of the problem I'm having.

To recap, I have a web site which allows clients to purchase copies of selected document images online. Once the transaction has been completed, I need to send the purchased document to the client browser. Images are in multipage TIFF format with group 4 compression. I have the image being delivered to the client browser, but what the client sees when they get the image is not at all correct.

Not at all correct, I realize, is rather vague. Results vary slightly from one browser/OS to another. On Win2k with IE 5.5, the default TIFF viewer for Windows reports that the document is not of a supported format. Using WinXP with IE 6, the default image viewer will recognize the proper number of pages in the image, but only the top 1/3 or so of the first page is actually readable (the rest of the image is black). If I save (and not view) the image with either Win2k or WinXP and then use a 3rd party image viewer to bring up the image, the results are similar to viewing the image with XP's default viewer.

I'm left to believe that either there is something wrong with my content header, or something is happening to the image during delivery to the browser. To be honest though, I think it's something I'm doing ;) Here's what I got thus far:

my $file = get_image_info($document); my $filesize = -s $file; my $buffer; # Read the image file open READ, "< $file" or die "Cannot open $file for reading: $!"; binmode READ; { local $/; $buffer = <READ>; } close(READ); # For Debugging Purposes print $request->header(), " ", length($buffer), " " , -s $file ;
I'm confident that the image reading portion of that is ok. When the debugging info gets sent to the browser, what Perl reports the size on disk to be (and the size of $buffer) match what the file size on disk actually is. Once I was sure that I was reading it ok, I worked on delivering the image. I have tried the following things listed below. Check the comment above each for the result.
# This didn't work. Displays "Save As" dialog twice, no image sent. print "Content-type: image/tiff\n"; print "Content-disposition: attachment; filename=image.tif\n\n"; print $buffer; # This kinda works. Displays "Save As" dialog twice, but image is # corruppted (see description in post). print "Content-Type: image/tiff; filename=image.tif\n"; print "Content-Disposition: attachment; filename=image.tif\n"; print "Content-Length: $filesize\n\n"; print $buffer; # Same result as above. print $request->header(-type => "image/tiff", -attachment=>'image.tif'), $buffer; # This almost works. Only displays "Save As" dialog once, image is # messed up though (see description in post). print "Content-Disposition: inline; filename=image.tif\n"; print "Content-Length: $filesize\n"; print "Content-Type: image/tiff\n\n"; print $buffer; # Same result as above, just done a bit differently. Changing the con +tent # type did nothing for me. print $request->header(-Content_Disposition => "inline; filename=image +.tif", -Content_Length => $filesize, -Content_Type => "application/octet-stream", ), $buffer;
Is there something obvious (or not so obvious) that I'm missing here? I spent the better part of yesterday combing through the Monastery looking for additional insight, but I can't find something different than what I've tried (or else I'm misapplying something that I've found there).

Any help, comments, or insight are very much appreciated. Thank you!

MrCromeDome


In reply to Downloading images to client PCs by MrCromeDome

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.