Y
Yehuda Berlinger
Hi. I am using the latest activestate perl, and I am trying to create
a client and a server that will do file uploading via http.
My client looks like:
my $UA = LWP::UserAgent->new;
my %fields = (fn => $fn, upload => [$upload]);
my $res = $UA->post($URL_Server, \%fields, 'Content_Type' =>
'form_data');
The server is running and receives the request. The file exists, is
readable, and is a binary file of about 4 MB. The server receives the
request, but the param list is empty. Something is there inside $cgi
called FORMDATA, but it is not accessible, and neither is the uploaded
file. Any ideas? Regular www-encoded requests work fine.
The server looks like this:
my $cgi = new CGI;
# upload is the same as param
my $file = $cgi->upload('upload');
binmode($file);
my $fn = $cgi->param('fn');
$fn = File::Spec->catfile($Dir,$fn);
# This returns a filehandle
my $fh = OpenForWriting({file=>$fn,nobackup=>1});
binmode($fh);
my ($bytesread,$buffer);
while ($bytesread=read($file,$buffer,1024))
{ print $fh $buffer; }
CloseForWriting($fh);
Any other comments also welcome.
Yehuda
a client and a server that will do file uploading via http.
My client looks like:
my $UA = LWP::UserAgent->new;
my %fields = (fn => $fn, upload => [$upload]);
my $res = $UA->post($URL_Server, \%fields, 'Content_Type' =>
'form_data');
The server is running and receives the request. The file exists, is
readable, and is a binary file of about 4 MB. The server receives the
request, but the param list is empty. Something is there inside $cgi
called FORMDATA, but it is not accessible, and neither is the uploaded
file. Any ideas? Regular www-encoded requests work fine.
The server looks like this:
my $cgi = new CGI;
# upload is the same as param
my $file = $cgi->upload('upload');
binmode($file);
my $fn = $cgi->param('fn');
$fn = File::Spec->catfile($Dir,$fn);
# This returns a filehandle
my $fh = OpenForWriting({file=>$fn,nobackup=>1});
binmode($fh);
my ($bytesread,$buffer);
while ($bytesread=read($file,$buffer,1024))
{ print $fh $buffer; }
CloseForWriting($fh);
Any other comments also welcome.
Yehuda