.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Amazon::S3::Bucket 3pm" .TH Amazon::S3::Bucket 3pm "2023-11-30" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Amazon::S3::Bucket \- A container class for a S3 bucket and its contents. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Amazon::S3; \& \& # creates bucket object (no "bucket exists" check) \& my $bucket = $s3\->bucket("foo"); \& \& # create resource with meta data (attributes) \& my $keyname = \*(Aqtesting.txt\*(Aq; \& my $value = \*(AqT\*(Aq; \& $bucket\->add_key( \& $keyname, $value, \& { content_type => \*(Aqtext/plain\*(Aq, \& \*(Aqx\-amz\-meta\-colour\*(Aq => \*(Aqorange\*(Aq, \& } \& ); \& \& # list keys in the bucket \& $response = $bucket\->list \& or die $s3\->err . ": " . $s3\->errstr; \& print $response\->{bucket}."\en"; \& for my $key (@{ $response\->{keys} }) { \& print "\et".$key\->{key}."\en"; \& } \& \& # check if resource exists. \& print "$keyname exists\en" if $bucket\->head_key($keyname); \& \& # delete key from bucket \& $bucket\->delete_key($keyname); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" .SH "METHODS AND SUBROUTINES" .IX Header "METHODS AND SUBROUTINES" .SS "new" .IX Subsection "new" Instaniates a new bucket object. .PP Pass a hash or hash reference containing various options: .IP "bucket (required)" 4 .IX Item "bucket (required)" The name (identifier) of the bucket. .IP "account (required)" 4 .IX Item "account (required)" The S3::Amazon object (representing the S3 account) this bucket is associated with. .IP "buffer_size" 4 .IX Item "buffer_size" The buffer size used for reading and writing objects to S3. .Sp default: 4K .IP "region" 4 .IX Item "region" If no region is set and \f(CW\*(C`verify_region\*(C'\fR is set to true, the region of the bucket will be determined by calling the \&\f(CW\*(C`get_location_constraint\*(C'\fR method. Note that this will decrease performance of the constructor. If you know the region or are operating in only 1 region, set the region in the \f(CW\*(C`account\*(C'\fR object (\f(CW\*(C`Amazon::S3\*(C'\fR). .IP "logger" 4 .IX Item "logger" Sets the logger. The logger should be a blessed reference capable of providing at least a \f(CW\*(C`debug\*(C'\fR and \f(CW\*(C`trace\*(C'\fR method for recording log messages. If no logger object is passed the \f(CW\*(C`account\*(C'\fR object's logger object will be used. .IP "verify_region" 4 .IX Item "verify_region" Indicates that the bucket's region should be determined by calling the \&\f(CW\*(C`get_location_constraint\*(C'\fR method. .Sp default: false .PP \&\fI\s-1NOTE:\s0\fR This method does not check if a bucket actually exists unless you set \f(CW\*(C`verify_region\*(C'\fR to true. If the bucket does not exist, the constructor will set the region to the default region specified by the Amazon::S3 object (\f(CW\*(C`account\*(C'\fR) that you passed. .PP Typically a developer will not call this method directly, but work through the interface in S3::Amazon that will handle their creation. .SS "add_key" .IX Subsection "add_key" .Vb 1 \& add_key( key, value, configuration) .Ve .PP Write a new or existing object to S3. .IP "key" 4 .IX Item "key" A string identifier for the object being written to the bucket. .IP "value" 4 .IX Item "value" A \s-1SCALAR\s0 string representing the contents of the object. .IP "configuration" 4 .IX Item "configuration" A \s-1HASHREF\s0 of configuration data for this key. The configuration is generally the \s-1HTTP\s0 headers you want to pass to the S3 service. The client library will add all necessary headers. Adding them to the configuration hash will override what the library would send and add headers that are not typically required for S3 interactions. .IP "acl_short (optional)" 4 .IX Item "acl_short (optional)" In addition to additional and overridden \s-1HTTP\s0 headers, this \&\s-1HASHREF\s0 can have a \f(CW\*(C`acl_short\*(C'\fR key to set the permissions (access) of the resource without a separate call via \&\f(CW\*(C`add_acl\*(C'\fR or in the form of an \s-1XML\s0 document. See the documentation in \f(CW\*(C`add_acl\*(C'\fR for the values and usage. .PP Returns a boolean indicating the sucess or failure of the call. Check \&\f(CW\*(C`err\*(C'\fR and \f(CW\*(C`errstr\*(C'\fR for error messages if this operation fails. To examine the raw output of the response from the \s-1API\s0 call, use the \&\f(CW\*(C`last_response()\*(C'\fR method. .PP .Vb 1 \& my $retval = $bucket\->add_key(\*(Aqfoo\*(Aq, $content, {}); \& \& if ( !$retval ) { \& print STDERR Dumper([$bucket\->err, $bucket\->errstr, $bucket\->last_response]); \& } .Ve .SS "add_key_filename" .IX Subsection "add_key_filename" The method works like \f(CW\*(C`add_key\*(C'\fR except the value is assumed to be a filename on the local file system. The file will be streamed rather then loaded into memory in one big chunk. .ie n .SS "copy_object %parameters" .el .SS "copy_object \f(CW%parameters\fP" .IX Subsection "copy_object %parameters" Copies an object from one bucket to another bucket. \fINote that the bucket represented by the bucket object is the destination.\fR Returns a hash reference to the response object (\f(CW\*(C`CopyObjectResult\*(C'\fR). .PP Headers returned from the request can be obtained using the \&\f(CW\*(C`last_response()\*(C'\fR method. .PP .Vb 1 \& my $headers = { $bucket\->last_response\->headers\->flatten }; .Ve .PP Throws an exception if the response code is not 2xx. You can get an extended error message using the \f(CW\*(C`errstr()\*(C'\fR method. .PP .Vb 2 \& my $result = eval { return $s3\->copy_object( key => \*(Aqfoo.jpg\*(Aq, \& source => \*(Aqboo.jpg\*(Aq ); }; \& \& if ($@) { \& die $s3\->errstr; \& } .Ve .PP Examples: .PP .Vb 1 \& $bucket\->copy_object( key => \*(Aqfoo.jpg\*(Aq, source => \*(Aqboo.jpg\*(Aq ); \& \& $bucket\->copy_object( \& key => \*(Aqfoo.jpg\*(Aq, \& source => \*(Aqboo.jpg\*(Aq, \& bucket => \*(Aqmy\-source\-bucket\*(Aq \& ); \& \& $bucket\->copy_object( \& key => \*(Aqfoo.jpg\*(Aq, \& headers => { \*(Aqx\-amz\-copy\-source\*(Aq => \*(Aqmy\-source\-bucket/boo.jpg\*(Aq \& ); .Ve .PP See CopyObject for more details. .PP \&\f(CW%parameters\fR is a list of key/value pairs described below: .IP "key (required)" 4 .IX Item "key (required)" Name of the destination key in the bucket represented by the bucket object. .IP "headers (optional)" 4 .IX Item "headers (optional)" Hash or array reference of headers to send in the request. .IP "bucket (optional)" 4 .IX Item "bucket (optional)" Name of the source bucket. Default is the same bucket as the destination. .IP "source (optional)" 4 .IX Item "source (optional)" Name of the source key in the source bucket. If not provided, you must provide the source in the `x\-amz\-copy\-source` header. .ie n .SS "head_key $key_name" .el .SS "head_key \f(CW$key_name\fP" .IX Subsection "head_key $key_name" Returns a configuration \s-1HASH\s0 of the given key. If a key does not exist in the bucket \f(CW\*(C`undef\*(C'\fR will be returned. .PP \&\s-1HASH\s0 will contain the following members: .IP "content_length" 4 .IX Item "content_length" .PD 0 .IP "content_type" 4 .IX Item "content_type" .IP "etag" 4 .IX Item "etag" .IP "value" 4 .IX Item "value" .PD .ie n .SS "delete_key $key_name" .el .SS "delete_key \f(CW$key_name\fP" .IX Subsection "delete_key $key_name" Permanently removes \f(CW$key_name\fR from the bucket. Returns a boolean value indicating the operations success. .ie n .SS "delete_keys @keys" .el .SS "delete_keys \f(CW@keys\fP" .IX Subsection "delete_keys @keys" .ie n .SS "delete_keys $keys" .el .SS "delete_keys \f(CW$keys\fP" .IX Subsection "delete_keys $keys" Permanently removes keys from the bucket. Returns the response body from the \s-1API\s0 call. Returns \f(CW\*(C`undef\*(C'\fR on non '2xx' return codes. .PP See .PP The argument to \f(CW\*(C`delete_keys\*(C'\fR can be: .IP "\(bu" 5 list of key names .IP "\(bu" 5 an array of hashes where each hash reference contains the keys \&\f(CW\*(C`Key\*(C'\fR and optionally \f(CW\*(C`VersionId\*(C'\fR. .IP "\(bu" 5 an array of scalars where each scalar is a key name .IP "\(bu" 5 a hash of options where the hash contains .IP "\(bu" 5 a callback that returns the key and optionally the version id .RS 5 .IP "quiet" 10 .IX Item "quiet" Boolean indicating quiet mode .IP "keys" 10 .IX Item "keys" An array of keys containing scalars or hashes as describe above. .RE .RS 5 .RE .PP Examples: .PP .Vb 2 \& # delete a list of keys \& $bucket\->delete_keys(qw( foo bar baz)); \& \& # delete an array of keys \& $bucket\->delete_keys([qw(foo bar baz)]); \& \& # delete an array of keys in quiet mode \& $bucket\->delete({ quiet => 1, keys => [ qw(foo bar baz) ]); \& \& # delete an array of versioned objects \& $bucket\->delete_keys([ { Key => \*(Aqfoo\*(Aq, VersionId => \*(Aq1\*(Aq} ]); \& \& # callback \& my @key_list = qw(foo => 1, bar => 3, biz => 1); \& \& $bucket\->delete_keys( \& sub { \& return ( shift @key_list, shift @key_list ); \& } \& ); .Ve .PP \&\fIWhen using a callback, the keys are deleted in bulk. The \&\f(CI\*(C`DeleteObjects\*(C'\fI \s-1API\s0 is only called once.\fR .SS "delete_bucket" .IX Subsection "delete_bucket" Permanently removes the bucket from the server. A bucket cannot be removed if it contains any keys (contents). .PP This is an alias for \f(CW\*(C`$s3\->delete_bucket($bucket)\*(C'\fR. .ie n .SS "get_key $key_name, [$method]" .el .SS "get_key \f(CW$key_name\fP, [$method]" .IX Subsection "get_key $key_name, [$method]" Takes a key and an optional \s-1HTTP\s0 method and fetches it from S3. The default \s-1HTTP\s0 method is \s-1GET.\s0 .PP The method returns \f(CW\*(C`undef\*(C'\fR if the key does not exist in the bucket and throws an exception (dies) on server errors. .PP On success, the method returns a \s-1HASHREF\s0 containing: .IP "content_type" 4 .IX Item "content_type" .PD 0 .IP "etag" 4 .IX Item "etag" .IP "value" 4 .IX Item "value" .ie n .IP "@meta" 4 .el .IP "\f(CW@meta\fR" 4 .IX Item "@meta" .PD .ie n .SS "get_key_filename $key_name, $method, $filename" .el .SS "get_key_filename \f(CW$key_name\fP, \f(CW$method\fP, \f(CW$filename\fP" .IX Subsection "get_key_filename $key_name, $method, $filename" This method works like \f(CW\*(C`get_key\*(C'\fR, but takes an added filename that the S3 resource will be written to. .SS "list" .IX Subsection "list" List all keys in this bucket. .PP See \*(L"list_bucket\*(R" in Amazon::S3 for documentation of this method. .SS "list_v2" .IX Subsection "list_v2" See \*(L"list_bucket_v2\*(R" in Amazon::S3 for documentation of this method. .SS "list_all" .IX Subsection "list_all" List all keys in this bucket without having to worry about \&'marker'. This may make multiple requests to S3 under the hood. .PP See \*(L"list_bucket_all\*(R" in Amazon::S3 for documentation of this method. .SS "list_all_v2" .IX Subsection "list_all_v2" Same as \f(CW\*(C`list_all\*(C'\fR but uses the version 2 \s-1API\s0 for listing keys. .PP See \*(L"list_bucket_all_v2\*(R" in Amazon::S3 for documentation of this method. .SS "get_acl" .IX Subsection "get_acl" Retrieves the Access Control List (\s-1ACL\s0) for the bucket or resource as an \s-1XML\s0 document. .IP "key" 4 .IX Item "key" The key of the stored resource to fetch. This parameter is optional. By default the method returns the \s-1ACL\s0 for the bucket itself. .SS "set_acl" .IX Subsection "set_acl" .Vb 1 \& set_acl(acl) .Ve .PP Retrieves the Access Control List (\s-1ACL\s0) for the bucket or resource. Requires a \s-1HASHREF\s0 argument with one of the following keys: .IP "acl_xml" 4 .IX Item "acl_xml" An \s-1XML\s0 string which contains access control information which matches Amazon's published schema. .IP "acl_short" 4 .IX Item "acl_short" Alternative shorthand notation for common types of ACLs that can be used in place of a \s-1ACL XML\s0 document. .Sp According to the Amazon S3 \s-1API\s0 documentation the following recognized acl_short types are defined as follows: .RS 4 .IP "private" 4 .IX Item "private" Owner gets \s-1FULL_CONTROL.\s0 No one else has any access rights. This is the default. .IP "public-read" 4 .IX Item "public-read" Owner gets \s-1FULL_CONTROL\s0 and the anonymous principal is granted \s-1READ\s0 access. If this policy is used on an object, it can be read from a browser with no authentication. .IP "public-read-write" 4 .IX Item "public-read-write" Owner gets \s-1FULL_CONTROL,\s0 the anonymous principal is granted \&\s-1READ\s0 and \s-1WRITE\s0 access. This is a useful policy to apply to a bucket, if you intend for any anonymous user to \s-1PUT\s0 objects into the bucket. .IP "authenticated-read" 4 .IX Item "authenticated-read" Owner gets \s-1FULL_CONTROL,\s0 and any principal authenticated as a registered Amazon S3 user is granted \s-1READ\s0 access. .RE .RS 4 .RE .IP "key" 4 .IX Item "key" The key name to apply the permissions. If the key is not provided the bucket \s-1ACL\s0 will be set. .PP Returns a boolean indicating the operations success. .SS "get_location_constraint" .IX Subsection "get_location_constraint" Returns the location constraint (region the bucket resides in) for a bucket. Returns undef if no location constraint. .PP Valid values that may be returned: .PP .Vb 10 \& af\-south\-1 \& ap\-east\-1 \& ap\-northeast\-1 \& ap\-northeast\-2 \& ap\-northeast\-3 \& ap\-south\-1 \& ap\-southeast\-1 \& ap\-southeast\-2 \& ca\-central\-1 \& cn\-north\-1 \& cn\-northwest\-1 \& EU \& eu\-central\-1 \& eu\-north\-1 \& eu\-south\-1 \& eu\-west\-1 \& eu\-west\-2 \& eu\-west\-3 \& me\-south\-1 \& sa\-east\-1 \& us\-east\-2 \& us\-gov\-east\-1 \& us\-gov\-west\-1 \& us\-west\-1 \& us\-west\-2 .Ve .PP For more information on location constraints, refer to the documentation for GetBucketLocation . .SS "err" .IX Subsection "err" The S3 error code for the last error the account encountered. .SS "errstr" .IX Subsection "errstr" A human readable error string for the last error the account encountered. .SS "error" .IX Subsection "error" The decoded \s-1XML\s0 string as a hash object of the last error. .SS "last_response" .IX Subsection "last_response" Returns the last \f(CW\*(C`HTTP::Response\*(C'\fR to an \s-1API\s0 call. .SH "MULTIPART UPLOAD SUPPORT" .IX Header "MULTIPART UPLOAD SUPPORT" From Amazon's website: .PP \&\fIMultipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without affecting other parts. After all parts of your object are uploaded, Amazon S3 assembles these parts and creates the object. In general, when your object size reaches 100 \s-1MB,\s0 you should consider using multipart uploads instead of uploading the object in a single operation.\fR .PP See for more information about multipart uploads. .IP "\(bu" 5 Maximum object size 5TB .IP "\(bu" 5 Maximum number of parts 10,000 .IP "\(bu" 5 Part numbers 1 to 10,000 (inclusive) .IP "\(bu" 5 Part size 5MB to 5GB. There is no limit on the last part of your multipart upload. .IP "\(bu" 5 Maximum nubmer of parts returned for a list parts request \- 1000 .IP "\(bu" 5 Maximum number of multipart uploads returned in a list multipart uploads request \- 1000 .PP A multipart upload begins by calling \&\f(CW\*(C`initiate_multipart_upload()\*(C'\fR. This will return an identifier that is used in subsequent calls. .PP .Vb 2 \& my $bucket = $s3\->bucket(\*(Aqmy\-bucket\*(Aq); \& my $id = $bucket\->initiate_multipart_upload(\*(Aqsome\-big\-object\*(Aq); \& \& my $part_list = {}; \& \& my $part = 1; \& my $etag = $bucket\->upload_part_of_multipart_upload(\*(Aqmy\-bucket\*(Aq, $id, $part, $data, length $data); \& $part_list{$part++} = $etag; \& \& $bucket\->complete_multipart_upload(\*(Aqmy\-bucket\*(Aq, $id, $part_list); .Ve .PP .Vb 1 \& upload_multipart_object( ... ) .Ve .PP Convenience routine \f(CW\*(C`upload_multipart_object\*(C'\fR that encapsulates the multipart upload process. Accepts a hash or hash reference of arguments. If successful, a reference to a hash that contains the part numbers and etags of the uploaded parts. .PP You can pass a data object, callback routine or a file handle. .IP "key" 5 .IX Item "key" Name of the key to create. .IP "data" 5 .IX Item "data" Scalar object that contains the data to write to S3. .IP "callback" 5 .IX Item "callback" Optionally provided a callback routine that will be called until you pass a buffer with a length of 0. Your callback will receive no arguments but should return a tuple consisting of a \fBreference\fR to a scalar object that contains the data to write and a scalar that represents the length of data. Once you return a zero length buffer the multipart process will be completed. .IP "fh" 5 .IX Item "fh" File handle of an open file. The file must be greater than the minimum chunk size for multipart uploads otherwise the method will throw an exception. .IP "abort_on_error" 5 .IX Item "abort_on_error" Indicates whether the multipart upload should be aborted if an error is encountered. Amazon will charge you for the storage of parts that have been uploaded unless you abort the upload. .Sp default: true .SS "abort_multipart_upload" .IX Subsection "abort_multipart_upload" .Vb 1 \& abort_multipart_upload(key, multpart\-upload\-id) .Ve .PP Abort a multipart upload .SS "complete_multipart_upload" .IX Subsection "complete_multipart_upload" .Vb 1 \& complete_multipart_upload(key, multpart\-upload\-id, parts) .Ve .PP Signal completion of a multipart upload. \f(CW\*(C`parts\*(C'\fR is a reference to a hash of part numbers and etags. .SS "initiate_multipart_upload" .IX Subsection "initiate_multipart_upload" .Vb 1 \& initiate_multipart_upload(key, headers) .Ve .PP Initiate a multipart upload. Returns an id used in subsequent call to \&\f(CW\*(C`upload_part_of_multipart_upload()\*(C'\fR. .SS "list_multipart_upload_parts" .IX Subsection "list_multipart_upload_parts" List all the uploaded parts of a multipart upload .SS "list_multipart_uploads" .IX Subsection "list_multipart_uploads" List multipart uploads in progress .SS "upload_part_of_multipart_upload" .IX Subsection "upload_part_of_multipart_upload" .Vb 1 \& upload_part_of_multipart_upload(key, id, part, data, length) .Ve .PP Upload a portion of a multipart upload .IP "key" 5 .IX Item "key" Name of the key in the bucket to create. .IP "id" 5 .IX Item "id" The multipart-upload id return in the \f(CW\*(C`initiate_multipart_upload\*(C'\fR call. .IP "part" 5 .IX Item "part" The next part number (part numbers start at 1). .IP "data" 5 .IX Item "data" Scalar or reference to a scalar that contains the data to upload. .IP "length (optional)" 5 .IX Item "length (optional)" Length of the data. .SH "SEE ALSO" .IX Header "SEE ALSO" Amazon::S3 .SH "AUTHOR" .IX Header "AUTHOR" Please see the Amazon::S3 manpage for author, copyright, and license information. .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Rob Lauer Jojess Fournier Tim Mullin Todd Rinaldo luiserd97 .SH "POD ERRORS" .IX Header "POD ERRORS" Hey! \fBThe above document had some coding errors, which are explained below:\fR .IP "Around line 1714:" 4 .IX Item "Around line 1714:" Unknown directive: =heads