|
NAMENet::Amazon::S3::Bucket - convenience object for working with Amazon S3 bucketsVERSIONversion 0.99SYNOPSISuse Net::Amazon::S3; my $bucket = $s3->bucket("foo"); ok($bucket->add_key("key", "data")); ok($bucket->add_key("key", "data", { content_type => "text/html", 'x-amz-meta-colour' => 'orange', })); # Enable server-side encryption ok($bucket->add_key("key", "data", { encryption => 'AES256', })); # the err and errstr methods just proxy up to the Net::Amazon::S3's # objects err/errstr methods. $bucket->add_key("bar", "baz") or die $bucket->err . $bucket->errstr; # fetch a key $val = $bucket->get_key("key"); is( $val->{value}, 'data' ); is( $val->{content_type}, 'text/html' ); is( $val->{etag}, 'b9ece18c950afbfa6b0fdbfa4ff731d3' ); is( $val->{'x-amz-meta-colour'}, 'orange' ); # fetch a part of the key $val = $bucket->get_key("key", { range => "bytes=1024-10240" }); # returns undef on missing or on error (check $bucket->err) is(undef, $bucket->get_key("non-existing-key")); die $bucket->errstr if $bucket->err; # fetch a key's metadata $val = $bucket->head_key("key"); is( $val->{value}, '' ); is( $val->{content_type}, 'text/html' ); is( $val->{etag}, 'b9ece18c950afbfa6b0fdbfa4ff731d3' ); is( $val->{'x-amz-meta-colour'}, 'orange' ); # delete a key ok($bucket->delete_key($key_name)); ok(! $bucket->delete_key("non-exist-key")); # delete the entire bucket (Amazon requires it first be empty) $bucket->delete_bucket; DESCRIPTIONThis module represents an S3 bucket. You get a bucket object from the Net::Amazon::S3 object.METHODSnewCreate a new bucket object. Expects a hash containing these two arguments:
add_keyTakes three positional parameters:
See Net::Amazon::S3::Operation::Object::Add::Request for details Returns a boolean. add_key_filenameUse this to upload a large file to S3. Takes three positional parameters:
Returns a boolean. copy_keyCreates (or replaces) a key, copying its contents from another key elsewhere in S3. Takes the following parameters:
edit_metadataChanges the metadata associated with an existing key. Arguments:
head_key KEYTakes the name of a key in this bucket and returns its configuration hashquery_string_authentication_uri KEY, EXPIRES_ATmy $uri = $bucket->query_string_authentication_uri ( key => 'foo', expires_at => time + 3_600, # valid for one hour ); my $uri = $bucket->query_string_authentication_uri ( key => 'foo', expires_at => time + 3_600, method => 'PUT', ); Returns uri presigned with your credentials. When used with Signature V4 you have to specify also HTTP method this presigned uri will be used for (default: "GET") Method provides authenticated uri only for direct object operations. Method follows API's "CALLING CONVENTION". Recognized positional arguments (mandatory).
Optional arguments
get_key $key_name [$method]Takes a key name and an optional HTTP method (which defaults to "GET". Fetches the key from AWS.On failure: Returns undef on missing content, throws an exception (dies) on server errors. On success: Returns a hashref of { content_type, etag, value, @meta } on success. Other values from the server are there too, with the key being lowercased. get_key_filename $key_name $method $filenameUse this to download large files from S3. Takes a key name and an optional HTTP method (which defaults to "GET". Fetches the key from AWS and writes it to the filename. THe value returned will be empty.On failure: Returns undef on missing content, throws an exception (dies) on server errors. On success: Returns a hashref of { content_type, etag, value, @meta } on success delete_key $key_nameRemoves $key from the bucket. Forever. It's gone after this.Returns true on success and false on failure delete_bucketDelete the current bucket object from the server. Takes no arguments.Fails if the bucket has anything in it. This is an alias for "$s3->delete_bucket($bucket)" listList all keys in this bucket.see "list_bucket" in Net::Amazon::S3 for documentation of this method. list_allList all keys in this bucket without having to worry about 'marker'. This may make multiple requests to S3 under the hood.see "list_bucket_all" in Net::Amazon::S3 for documentation of this method. get_aclTakes one optional positional parameter
Returns an acl in XML format. set_aclTakes a configuration hash_ref containing:
Returns a boolean. get_location_constraintRetrieves the location constraint set when the bucket was created. Returns a string (eg, 'EU'), or undef if no location constraint was set.errThe S3 error code for the last error the object ran intoerrstrA human readable error string for the last error the object ran intoadd_tags# Add tags for a bucket $s3->add_tags ({ bucket => 'bucket-name', tags => { tag1 => 'value-1', tag2 => 'value-2' }, }); # Add tags for an object $s3->add_tags ({ bucket => 'bucket-name', key => 'key', tags => { tag1 => 'value-1', tag2 => 'value-2' }, }); Takes configuration parameters
Returns "true" on success. Returns "false" and sets "err"/"errstr" otherwise. delete_tags# Add tags for a bucket $s3->delete_tags ({ bucket => 'bucket-name', }); # Add tags for an object $s3->delete_tags ({ bucket => 'bucket-name', key => 'key', version_id => $version_id, }); Takes configuration parameters
Returns "true" on success. Returns "false" and sets "err"/"errstr" otherwise. SEE ALSONet::Amazon::S3AUTHORBranislav Zahradník <barney@cpan.org>COPYRIGHT AND LICENSEThis software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Visit the GSP FreeBSD Man Page Interface. |