Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

JPEG cgi problem

by mouser13 (Novice)
on Oct 28, 2012 at 14:47 UTC ( #1001270=perlquestion: print w/replies, xml ) Need Help??
mouser13 has asked for the wisdom of the Perl Monks concerning the following question:

Hello I'm having a bit of issue I have thrid party program that builds a JPEG(JFIF really). For some reason when I try to read it in perl binmode it removes the header information. Server code recieves plot to build and passes back the image data
print `/cwms/s0cwmsxx/v1.5.01/bin/dssVue $ /cwms/g7cwmspd/plot +Files/files/$num`; print "After command\n"; open(FH, "/cwms/g7cwmspd/plotFiles/files/$num.jpg"); binmode(FH); my $buf; while(<FH>) { read(FH,$buf,500); print $buf; print $client $buf; }
client(cgi) sends the message to build the plot and print out the image
print "Content-type: image/jpeg\n\n"; print $socket "$MESSAGE\n"; read($socket, $buffer,2097152); print "Content-type: image/jpeg\n\n"; print substr($buffer,1); open (OUTIMAGE,">/usr26/wcdb/log/plottest.jpg"); binmode(OUTIMAGE); print OUTIMAGE substr($buffer,1); close(OUTIMAGE);
Any ideas why I'm not getting the first 200 or so bytes of header information? Ie.I ftp both files one created by the thrid party program and the one from my reading it. The one created by the thrid party program starts JFIF    C  and is 77,737. Looking closely it does have The below in it. So to me it looks like for somereason binmode perl is not read maybe the header information of the JPEG? My reading starts   } !1AQa"q2#BR$3br and is 77,528 bytes and doesn't work correctly.

Replies are listed 'Best First'.
Re: JPEG cgi problem
by NetWallah (Canon) on Oct 28, 2012 at 15:14 UTC
    Your "while(<FH>)" is reading a record into $_, which you are not using.

    Change to:

    while( ! eof FH )
    or the equivalent.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Re: JPEG cgi problem
by aitap (Curate) on Oct 28, 2012 at 20:49 UTC
    Please post hexdumps if you want to show binary data.
    Sorry if my advice was wrong.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001270]
Approved by Corion
and the questions are moot...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-06-25 20:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (128 votes). Check out past polls.