AWS-S3
view release on metacpan or search on metacpan
lib/AWS/S3/Request/SetFileContents.pm view on Meta::CPAN
package AWS::S3::Request::SetFileContents;
use Moose;
use AWS::S3::ResponseParser;
with 'AWS::S3::Roles::Request';
has 'bucket' => (
is => 'ro',
isa => 'AWS::S3::BucketName',
required => 1,
);
has 'file' => (
is => 'ro',
isa => 'AWS::S3::File',
required => 1,
);
has 'content_type' => (
is => 'ro',
isa => 'Str',
required => 1,
lazy => 1,
default => sub { 'binary/octet-stream' },
);
has '+_expect_nothing' => ( default => 0 );
sub request {
my $s = shift;
my $contents;
if ( ref( $s->file->contents ) eq 'CODE' ) {
$contents = $s->file->contents->();
} elsif ( ref( $s->file->contents ) eq 'SCALAR' ) {
$contents = $s->file->contents;
} # end if()
my %other_args = ();
$other_args{'x-amz-server-side-encryption'} = 'AES256' if $s->file->is_encrypted;
# the key must be escaped, otherwise characters such as "?" or "#" in it
# change the meaning of the request (e.g. a key of "foo?acl" would become
# a PUT of the "acl" subresource rather than an upload of an object)
my $uri = $s->protocol . '://' . $s->bucket . '.' . $s->endpoint . '/' . $s->_escape_key( $s->file->key );
$s->_send_request(
PUT => URI->new( $uri ) => {
Date => $s->_http_date,
'content-type' => $s->content_type,
'content-md5' => $contents ? $s->_content_md5( $$contents ) : '',
'x-amz-storage-class' => $s->file->storage_class,
},
$$contents
);
} # end request()
__PACKAGE__->meta->make_immutable;
( run in 1.022 second using v1.01-cache-2.11-cpan-eb134014566 )