Amazon-S3-Thin

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


**Returns**: an [HTTP::Response](https://metacpan.org/pod/HTTP%3A%3AResponse) object for the request.

This method is a variation of the PUT operation as described by
Amazon's S3 API. It creates a copy of an object that is already stored
in Amazon S3. This "PUT copy" operation is the same as performing a GET
from the old bucket/key and then a PUT to the new bucket/key.

Note that the COPY request might return error response in 200 OK, but this method
will determine the error response and rewrite the status code to 500.

For more information, please refer to
[Amazon's documentation for COPY](http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html).

## put\_object( $bucket, $key, $content \[, $headers\] )

**Arguments**:

- 1. bucket - a string with the destination bucket
- 2. key - a string with the destination key
- 3. content - a string with the content to be uploaded
- 4. headers (**optional**) - hashref with extra header information

**Returns**: an [HTTP::Response](https://metacpan.org/pod/HTTP%3A%3AResponse) object for the request.

The PUT operation adds an object to a bucket. Amazon S3 never adds partial
objects; if you receive a success response, Amazon S3 added the entire
object to the bucket.

For more information, please refer to
[Amazon's documentation for PUT](http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html).

## delete\_multiple\_objects( $bucket, @keys )

**Arguments**: a string with the bucket name, and an array with all the keys
to be deleted.

**Returns**: an [HTTP::Response](https://metacpan.org/pod/HTTP%3A%3AResponse) object for the request.

The Multi-Object Delete operation enables you to delete multiple objects
(up to 1000) from a bucket using a single HTTP request. If you know the
object keys that you want to delete, then this operation provides a suitable
alternative to sending individual delete requests with `delete_object()`,
reducing per-request overhead.

For more information, please refer to
[Amazon's documentation for DELETE multiple objects](http://docs.aws.amazon.com/AmazonS3/latest/API/multiobjectdeleteapi.html).

## list\_objects( $bucket \[, \\%options \] )

**Arguments**: a string with the bucket name, and (optionally) a hashref
with any of the following options:

- `prefix` (_string_) - only return keys that begin with the
specified prefix. You can use prefixes to separate a bucket into different
groupings of keys, the same way you'd use a folder in a file system.
- `delimiter` (_string_) - group keys that contain the same string
between the beginning of the key (or after the prefix, if specified) and the
first occurrence of the delimiter.
- `encoding-type` (_string_) - if set to "url", will encode keys
in the response (useful when the XML parser can't work unicode keys).
- `marker` (_string_) - specifies the key to start with when listing
objects. Amazon S3 returns object keys in alphabetical order, starting with
the key right after the marker, in order.
- `max-keys` (_string_) - Sets the maximum number of keys returned
in the response body. You can add this to your request if you want to
retrieve fewer than the default 1000 keys.

**Returns**: an [HTTP::Response](https://metacpan.org/pod/HTTP%3A%3AResponse) object for the request. Use the `content()`
method on the returned object to read the contents:

This method returns some or all (up to 1000) of the objects in a bucket. Note
that the response might contain fewer keys but will never contain more.
If there are additional keys that satisfy the search criteria but were not
returned because the limit (either 1000 or max-keys) was exceeded, the
response will contain `<IsTruncated>true</IsTruncated>`. To return the
additional keys, see `marker` above.

For more information, please refer to
[Amazon's documentation for REST Bucket GET](https://metacpan.org/pod/%20http%3A#docs.aws.amazon.com-AmazonS3-latest-API-RESTBucketGET.html).

## generate\_presigned\_post( $bucket, $key \[, $fields, $conditions, $expires\_in \] )

**Arguments**:

- 1. bucket (_string_) - a string with the destination bucket
- 2. key (_string_) - a string with the destination key
- 3. fields (_arrayref_) - an arrayref of key/value pairs to prefilled form fields to build on top of
- 4. conditions (_arrayref_) - an arrayref of condition (arrayref or hashref) to include in the policy
- 5. expires\_in (_number_) - a number of seconds from the current time before expiring presigned url

**Returns**: a hashref with two elements `url` and `fields`. `url` is the url to post to. `fields` is an arrayref
filled with the form fields and respective values to use when submitting the post. (You must follow the order of `fields`)

This method generates presigned url for uploading a file to Amazon S3 using HTTP POST.
The original implementation from boto3, this was transplanted referencing [S3Client.generate\_presigned\_post()](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.generate_presigned_post).

Note: this method is supported only signature v4.

This is an example of generating a presigned url and uploading `test.txt` file.
In this case, you can set the object metadata `x-amz-meta-foo` with any value and the uploading size is limited to 1MB.

    my $presigned = $s3->generate_presigned_post('my.bucket', 'my/key.ext', [
        'x-amz-meta-foo' => 'bar',
    ], [
        ['starts-with' => '$x-amz-meta-foo', ''],
        ['content-length-range' => 1, 1024*1024],
    ], 24*60*60);

    my $ua = LWP::UserAgent->new;
    my $res = $ua->post(
        $presigned->{url},
        Content_Type => 'multipart/form-data',
        Content      => [
            @{$presigned->{fields}},
            file => ['test.txt'],
        ],
    );

For more information, please refer to
[Amazon's documentation for Creating a POST Policy](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html).



( run in 0.489 second using v1.01-cache-2.11-cpan-99c4e6809bf )