-
-
Save phillipadsmith/ef28cf3702613cc85fa7 to your computer and use it in GitHub Desktop.
Post multipart/form-data with Mojo::UserAgent
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
# Trying to copy this Ruby example: | |
#RestClient.post('https://ME%40TEST.COM:SECRET@www.documentcloud.org/api/upload.json', | |
#:file => File.new('/full/path/to/document/document.pdf','rb'), | |
#:title => "2008 Blagojevich Tax Return", | |
#:source => "U.S. Attorney's Office", | |
#:access => 'private', | |
#:data => {"date" => "2009-04-01", "exhibit" => "E1146"} | |
#) | |
my $ua = Mojo::UserAgent->new; | |
my $tx = $ua->post( | |
'user:password@www.documentcloud.org/api/upload.json' => | |
form => { | |
file => 'http://www.openinfo.gov.bc.ca/local/ibc/docs/Part%202.pdf', | |
title => | |
'Review of the Draft Multicultural Strategic Outreach Plan, Part 2' | |
} | |
); | |
if (my $res = $tx->success) { say $res->body } | |
else { | |
my ($err, $code) = $tx->error; | |
say $code ? "$code response: $err" : "Connection error: $err"; | |
} | |
# Keep getting: 400 response: Bad Request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment