Last active
September 4, 2015 02:55
A small cookbook program showing how to upload files with Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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