AWS-S3
view release on metacpan or search on metacpan
lib/AWS/S3/File.pm view on Meta::CPAN
sub signed_url {
my $s = shift;
my $expires = shift || 3600;
# expiry for v4 signature is in seconds, not epoch time
if ( $expires > time ) {
$expires -= time;
}
my $key = $s->key;
if ( ! $s->bucket->s3->honor_leading_slashes ) {
$key =~ s!^/!!;
}
my $type = "GetPreSignedUrl";
my $uri = $s->bucket->s3->request(
$type,
bucket => $s->bucket->name,
key => $key,
expires => $expires,
)->request;
return $uri;
}
sub delete {
my $s = shift;
my $type = 'DeleteFile';
my $req = $s->bucket->s3->request(
$type,
bucket => $s->bucket->name,
key => $s->key,
);
my $response = $req->request();
if ( my $msg = $response->friendly_error() ) {
die $msg;
} # end if()
return 1;
} # end delete()
__PACKAGE__->meta->make_immutable;
__END__
=pod
=head1 NAME
AWS::S3::File - A single file in Amazon S3
=head1 SYNOPSIS
my $file = $bucket->file('foo/bar.txt');
# contents is a scalarref:
print @{ $file->contents };
print $file->size;
print $file->key;
print $file->etag;
print $file->lastmodified;
print $file->owner->display_name;
print $file->bucket->name;
# Set the contents with a scalarref:
my $new_contents = "This is the new contents of the file.";
$file->contents( \$new_contents );
# Set the contents with a coderef:
$file->contents( sub {
return \$new_contents;
});
# Alternative update
$file->update(
contents => \'New contents', # optional
contenttype => 'text/plain' # optional
);
# Get signed URL for the file for public access
print $file->signed_url( $expiry_time );
# Delete the file:
$file->delete();
=head1 DESCRIPTION
AWS::S3::File provides a convenience wrapper for dealing with files stored in S3.
=head1 PUBLIC PROPERTIES
=head2 bucket
L<AWS::S3::Bucket> - read-only.
The L<AWS::S3::Bucket> that contains the file.
=head2 key
String - read-only.
The 'filename' (for all intents and purposes) of the file.
=head2 size
Integer - read-only.
The size in bytes of the file.
=head2 etag
String - read-only.
The Amazon S3 'ETag' header for the file.
=head2 owner
L<ASW::S3::Owner> - read-only.
The L<ASW::S3::Owner> that the file belongs to.
=head2 storage_class
String - read-only.
The type of storage used by the file.
=head2 lastmodified
String - read-only.
A date in this format:
2009-10-28T22:32:00
=head2 contents
ScalarRef|CodeRef - read-write.
Returns a scalar-reference of the file's contents.
( run in 0.701 second using v1.01-cache-2.11-cpan-5a3173703d6 )