LWP, CGI and file uploads under windows

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
 
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');

Someone found the answer for me in another group. The above should
change 'form_data' to 'multipart/form-data' . (note the '-' also,
instead of the '_')

Yehuda Berlinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top