Hi all... I'm trying to HTTP post a jpg image using the code below. However, when the file reaches the destination server, it becomes corrupted. Does anyone know how to resolve this issue? Thanks! Shinobu.
sub pushToImageServer { my $imageFullPath = $_[0]; my $imageFileName = $_[1]; my $contentType = $_[2]; my $userName = $_[3]; my $fileNameNoExt = $_[4]; my $FAILURE = 'Response: Failed'; my $SUCCESS = 'Response: Success'; logEvent(qq(Pushing "$imageFileName" to $CONFIGURATION->{imageserv +er})) if $CONFIGURATION->{verbose}; #my $CONFIGURATION->{imageserver}Path = "/up/" . $CONFIGURATION->{ +password} . "/" . $CONFIGURATION->{application} . "/" . $imageFileNam +e; my $imageServerPath = "/up/" . $CONFIGURATION->{password} . "/" . +$CONFIGURATION->{application} . "/" . $userName . "/"; ## CS URL ##my $URL = 'http://' . $CONFIGURATION->{imageserver} . $imageServ +erPath; ## IS URL ##$imageServerPath =~ s/\/$//; ## Strip off trailing slash my $URL = 'http://' . $CONFIGURATION->{imageserver} . $imageServer +Path . "?width=" . $CONFIGURATION->{validimagewidth} . "&height=" . $ +CONFIGURATION->{validimageheight} . "&type=" . $CONFIGURATION->{desir +edformat} . "&name=" . $fileNameNoExt; logEvent("Image Server URL: $URL") if $CONFIGURATION->{verbose}; ## POST my $ua = LWP::UserAgent->new; my $imageBody = [$CONFIGURATION->{filekey}=>[$imageFullPath,$image +FileName,'Content-Type'=>$contentType]]; my $POST = POST($URL, Content_Type => 'form-data',Connection => 'C +lose',Host => $CONFIGURATION->{imageserver}, Content=>$imageBody); ## GET my $return = $ua->request($POST); my $returnString = $return->as_string; #logEvent("Received From $CONFIGURATION->{imageserver}: $returnStr +ing"); logEvent("Received From $CONFIGURATION->{imageserver}: $returnStri +ng") if $CONFIGURATION->{verbose}; unless ( $returnString =~ /$SUCCESS/ ) { logEvent("Received FAILURE Response from $CONFIGURATION->{imag +eserver}"); return 0; } return 1; }

In reply to Cannot post image using LWP by shinobu

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.