I have read many nodes regarding file upload. I use 'strict' as much as possible.

I thought that there would be no problem integrating LWP on the client side and CGI on the server side but this does not seem to be the case.

I am using a call like this on the client:

my $enctype = 'form-data/multipart'; $ua = LWP::UserAgent->new; $req = POST $url, Content_Type => $enctype, Content => [ p_progra_idint =>$p_progra_idint, p_upload => [$path_file,$name_file] ]; $res = $ua->request($req);

And on the server side:

$CGI::DISABLE_UPLOADS = 0; $ENV{'TMPDIR'} = $tpath; binmode(STDIN); $req = new CGI(\*STDIN); my $fh = $req->upload('p_upload'); my $buffer; open (OUTFILE, ">$path_sortida") or die "Unable to create upload output file $! \n"; binmode $fh; binmode OUTFILE; my ($bytes, $read); $bytes = 0; while ($read = read ($fh, $buffer, 16384)) { print OUTFILE $buffer; $bytes += $read; } close OUTFILE;
Strangely, if I use 'form-data/multipart' all variables except the file are read perfectly on the server side, on the other hand if I use 'multipart/form-data' (which is what it should be) all sorts of erroneous variables are read.

With the first option as encoding, all vars are read, but 0 bytes of the file are returned after the bucle. The file is created but with zero size.

I have browsed the perlmonks archives and tutorials as well as done some obvious google querys, now I am lost and I am thinking on doing the parsing by hand on the server (ugh).

Thanks in advance.


In reply to Yet another file-upload question (using LPW--->CGI) by dani++

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.