Skip to content

Instantly share code, notes, and snippets.

@phillipadsmith
Created June 12, 2013 22:21
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 phillipadsmith/ef28cf3702613cc85fa7 to your computer and use it in GitHub Desktop.
Save phillipadsmith/ef28cf3702613cc85fa7 to your computer and use it in GitHub Desktop.
Post multipart/form-data with Mojo::UserAgent
# 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