public
Last active

A small cookbook program showing how to upload files with Perl

  • Download Gist
file-upload.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/usr/bin/perl
 
use strict;
use warnings;
 
# This is intended as an easy-to-use cookbook example to getting started
# uploading files on Perl. Please let me (gaurav at ggvaidya dot com) know
# if you have any comments or suggestions for this example.
#
# It is made available under the same license terms as the Perl interpreter.
 
use WWW::Mechanize;
 
my $mech = new WWW::Mechanize(
autocheck => 1 # If set to 1, WWW::Mechanize will produce its
# own error messages.
);
 
# For more information on how $file works, please check out
# see http://search.cpan.org/perldoc?HTTP::Request::Common#POST
my $file = [
'filename-on-disk.txt', # The file you'd like to upload.
'filename-for-upload.txt', # The filename you'd like to give the web server.
'Content-type' => 'text/plain' # Any other flags you'd like to add go here.
];
 
$mech->post("http://127.0.0.1:8080/upload.cgi",
'Content_Type' => 'form-data',
'Content' => [
'upload' => $file
]
);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.