Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created August 26, 2013 18:43
Show Gist options
  • Save aanoaa/6344985 to your computer and use it in GitHub Desktop.
Save aanoaa/6344985 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use HTTP::Tiny;
use Path::Tiny;
use Try::Tiny;
use MIME::Base64;
{
my $boundary = '----WebKitFormBoundaryePkpFF7tjBAqx29L';
my $http = HTTP::Tiny->new(
agent => 'hello-world/0.0.0',
default_headers => {
'accept' => 'application/json',
'content-type' => "multipart/form-data; boundary=$boundary",
},
);
my $params = $http->www_form_urlencode({
access_token => 'DKLxqsBjKIRGlVgWVweWdsajLc_NaRY8',
study => 'perfusion',
imagetype => 'CT',
subject => 'PCT01001',
md5sum => 'this is md5sum',
});
my $content =
"--$boundary"
. "\r\n"
. qq{Content-Disposition: form-data; name="bundle"; filename=".bashrc"}
. "\r\n"
. qq{Content-Transfer-Encoding: base64}
. "\r\n"
. qq{Content-Type: application/octet-stream}
. "\r\n"
. "\r\n"
. encode_base64( path( '/home/hshong/.bashrc' )->slurp_raw )
. "\r\n"
. "--$boundary--"
. "\r\n";
my $res = $http->post(
"http://localhost:5000/api/bundle?$params",
{
content => (
$content
),
},
);
use DDP;
p $res;
die $res->{reason} unless $res->{success};
my $data
= try { decode_json( $res->{content} ) }
catch { die "Failed To Decode Response Content: $_"; }
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment