Amazon-S3-Thin
view release on metacpan or search on metacpan
lib/Amazon/S3/Thin/Signer/V2.pm view on Meta::CPAN
return MIME::Base64::encode_base64($hmac->digest, '');
}
sub string_to_sign {
my ($self, $method, $path, $headers, $expires) = @_;
my %interesting_headers = ();
while (my ($key, $value) = each %$headers) {
my $lk = lc $key;
if ( $lk eq 'content-md5'
or $lk eq 'content-type'
or $lk eq 'date'
or $lk =~ /^$AMAZON_HEADER_PREFIX/)
{
$interesting_headers{$lk} = $self->_trim($value);
}
}
# these keys get empty strings if they don't exist
$interesting_headers{'content-type'} ||= '';
$interesting_headers{'content-md5'} ||= '';
# x-amz-date becomes date if it exists
$interesting_headers{'date'} = delete $interesting_headers{'x-amz-date'}
if exists $interesting_headers{'x-amz-date'};
# if you're using expires for query string auth, then it trumps date
# (and x-amz-date)
$interesting_headers{'date'} = $expires if $expires;
t/02_signer_v2.t view on Meta::CPAN
my $content_encoding = "gzip";
my $content_length = 5913339;
my $string_to_sign = "PUT\n4gJE4saaMU4BqNR0kLY+lw==\napplication/x-download\nTue, 27 Mar 2007 21:06:08 +0000\nx-amz-acl:public-read\nx-amz-meta-checksumalgorithm:crc32\nx-amz-meta-filechecksum:0x02661779\nx-amz-meta-reviewedby:joe\@johnsmith.net,...
my $signer = Amazon::S3::Thin::Signer::V2->new($credentials);
my $hdr = HTTP::Headers->new;
$hdr->header("Date", $date);
$hdr->header("User-Agent", $user_agent);
$hdr->header("x-amz-acl", $x_amz_acl);
$hdr->header("content-type", $content_type);
$hdr->header("Content-MD5", $content_md5);
$hdr->header("X-Amz-Meta-ReviewedBy", join(',' => @x_amz_meta_reviewed_by));
$hdr->header("X-Amz-Meta-FileChecksum", $x_amz_meta_filechecksum);
$hdr->header("X-Amz-Meta-ChecksumAlgorithm", $x_amz_meta_checksum_algorithm);
$hdr->header("Content-Disposition", $content_disposition);
$hdr->header("Content-Encoding", $content_encoding);
$hdr->header("Content-Length", $content_length);
is(
$signer->string_to_sign($verb,$path,$hdr),
xt/92_presigned_post.t view on Meta::CPAN
return $ua->post(
$presigned->{url},
Content_Type => 'multipart/form-data',
Content => [
@{$presigned->{fields}},
file => [$filename],
],
);
}
subtest 'upload with content-type and metadata' => sub {
my $key = 'upload.txt';
my $presigned = $client->generate_presigned_post($bucket, $key, [
'Content-Type' => 'image/png',
'x-amz-meta-foo' => 'bar',
], [
['starts-with' => '$x-amz-meta-foo', ''],
['starts-with' => '$Content-Type', 'image/'],
]);
my $res = upload($presigned);
is $res->code, 204, 'upload via presigned url';
$res = $client->get_object($bucket, $key);
is $res->code, 200, 'get uploaded object';
is $res->content, $content;
is $res->header('content-type'), 'image/png';
is $res->header('x-amz-meta-foo'), 'bar';
$res = $client->delete_object($bucket, $key);
is $res->code, 204, 'delete uploaded object';
};
subtest 'upload with filename foo-${filename}' => sub {
my $presigned = $client->generate_presigned_post($bucket, 'foo-${filename}', [], []);
my $res = upload($presigned);
( run in 2.114 seconds using v1.01-cache-2.11-cpan-524268b4103 )