Skip to content

Instantly share code, notes, and snippets.

@gaurav
Last active September 4, 2015 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaurav/253111 to your computer and use it in GitHub Desktop.
Save gaurav/253111 to your computer and use it in GitHub Desktop.
A small cookbook program showing how to upload files with Perl
#!/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
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment