Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Yet another file-upload question (using LPW--->CGI)

by dani++ (Sexton)
CGI) NODE.owner = 55982 N.title = monktitlebar sitedoclet N.owner = 17342 -->
on Jul 17, 2002 at 09:38 UTC ( [id://182364]=perlquestion: print w/replies, xml ) Need Help??

dani++ has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: Yet another file-upload question (using LPW--->CGI)
by amphiplex (Monk) on Jul 17, 2002 at 10:40 UTC
    Hi !

    Maybe I am missing something here, but your scripts worked for me when I removed the
    (\*STDIN)
    Why did you do that ?

    The encoding type is definitely
    multipart/form-data

    ---- amphiplex
      YAY! I did just that as well.

      'Yet Another Stupid Mistake(tm)' on my part.

      Thanks a lot though.

Re: Yet another file-upload question (using LPW--->CGI)
by dani++ (Sexton) on Jul 17, 2002 at 10:11 UTC
    (Update):

    Uh, using 'form-data/multipart' sends the query without the binary. However, using the correct 'multipart/form-data' sends a correct looking query (with the binary) which confuses 'CGI.pm' big time.

    Saving the received query 'as is' and doing a 'vi' on it shows that all the end of lines are in binary (^M in vi) but CGI does not seem to recognize them, the bastard.

    ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://182364]
Approved by zejames
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 20:55 GMT
Sections?
CGI) NODE.owner = 55982 N.title = Sections sitedoclet N.owner = 17342 -->
Information?
CGI) NODE.owner = 55982 N.title = Information sitedoclet N.owner = 17342 -->
Find Nodes?
CGI) NODE.owner = 55982 N.title = Find Nodes sitedoclet N.owner = 17342 -->
Leftovers?
    CGI) NODE.owner = 55982 N.title = Leftovers sitedoclet N.owner = 17342 -->
    Voting Booth?

    No recent polls found