Reputation: 437
I have a Perl script with a call my $file_handle = $cgi->upload('uploaded_file')
. Is there a way to test this script from command line before deploying to the web server? I looked at (How can I send POST and GET data to a Perl CGI script via the command line?) and other questions, but could not find any information for passing a file for upload from the command line. Thanks in advance for the help.
Upvotes: 1
Views: 750
Reputation: 39158
A file upload is just another POST request! See DEBUGGING in CGI.pm. The program is index.pl
, the file to upload is somefile.bin
and the form field name is uploaded_file
:
REQUEST_METHOD=POST \
CONTENT_TYPE='multipart/form-data; boundary=xYzZY' \
perl index.pl < <(
perl -MHTTP::Request::Common=POST -e'
print POST(
undef,
Content_Type => "form-data",
Content => [ uploaded_file => [ "somefile.bin" ]]
)->content
'
)
Upvotes: 3