in reply to testing CGI.pm file uploads?

Tie a filehandle. Stick the text of an HTTP POST with an uploaded file in there. Pass the filehandle to CGI->new(). Process the upload as you normally would. Check to see that you've received the file as usual.

Replies are listed 'Best First'.
Re: Re: testing CGI.pm file uploads?
by markjugg (Curate) on Apr 11, 2003 at 17:53 UTC
    Thanks chromatic, Your suggestion got me poking around to create such a file. Here's some starter code for someone else wanting to do this:
    use HTTP::Request::Common; use LWP::UserAgent; # This form data will be printed to STDOUT my $r = POST 'http://www.perl.org/survey.cgi', Content_Type => 'form-data', Content => [ name => 'Gisle Aas', email => 'gisle@aas.no', gender => 'M', born => '1964', init => ["$ENV{HOME}/.profile"], ]; print $r->as_string;

    -mark

Re: Re: testing CGI.pm file uploads?
by markjugg (Curate) on Apr 11, 2003 at 18:15 UTC
    While this approach made sense to me, it didn't turn out to work as expected. It looks like the CGI.pm "new" function is expecting a basic name/value format from the file handle, and can't currently handle a raw HTTP POST request.

    Another approach that occured to me is to capture the environment variables of a real HTTP POST, and then set them again inside the test script.

    -mark