For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > February 2006 > How can I pass a file handle in a URL?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How can I pass a file handle in a URL?
Mark Calleja

2006-02-21, 7:55 am

G'day,

I've got a CGI script that accepts a form, including a file handle,
hence allowing users to upload files, but I'm having trouble passing the
request in a URL request. The request is generated by a script using
HTTP (no HTML is used in the process), and works with the LWP module by
having something like the following in the client (showing only
essential detail):

use LWP;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;

my $res = $ua->request(
POST $external_url,
Content_Type => 'form-data',
Content =>
[
upload_file => [ $filepath ],
user => $userid,
action => $action,
]
);

So the above client code works fine, but the following alternative fails:

my $req = HTTP::Request->new(POST => "$external_url");
$req->content_type('application/x-www-form-urlencoded');
$req->content("upload_file=$filepath&user=$userid&action=$action");
my $res = $ua->request($req);

On the server side, the CGI scipt basically loads the uploaded file via
(showing only essential detail):

use CGI qw(:standard);
my $q = new CGI;
my $fh_payload = $q->upload('upload_file');

Is there any reason why the second method (using the encoded URL) fails
while the first method succeeds? More importantly, can anyone suggest a
way of making the second method work?

Cheers,
Mark
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com