[Israel.pm] LWP. CGI and file uploads under windows

jon at actcom.co.il jon at actcom.co.il
Wed Jan 28 07:40:49 PST 2004

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' =>

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?

The server looks like this:

	my $cgi = new CGI;

# upload is the same as param
	my $file = $cgi->upload('upload');

	my $fn = $cgi->param('fn');
	$fn = File::Spec->catfile($Dir,$fn);

# This returns a filehandle
	my $fh = OpenForWriting({file=>$fn,nobackup=>1});

	my ($bytesread,$buffer);
	while ($bytesread=read($file,$buffer,1024))
		{ print $fh $buffer; }

Any other comments also welcome.


More information about the Perl mailing list