Net::Async::Webservice::S3 - use Amazon's S3 web service with IO::Async
Net::Async::Webservice::S3
IO::Async
TODO
This module provides a webservice API around Amazon's S3 web service for use in an IO::Async-based program. Each S3 operation is represented by a method that returns a Future; this future, if successful, will eventually return the result of the operation.
The following named parameters may be passed to new or configure:
new
configure
Optional. Allows the caller to provide a specific asynchronous HTTP user agent object to use. This will be invoked with a single method, as documented by Net::Async::HTTP:
$response_f = $http->do_request( request => $request, ... )
If absent, a new instance will be created and added as a child notifier of this object. If a value is supplied, it will be used as supplied and not specifically added as a child notifier. In this case, the caller must ensure it gets added to the underlying IO::Async::Loop instance, if required.
The twenty-character Access Key ID and forty-character Secret Key to use for authenticating requests to S3.
Optional. If supplied, gives the default bucket name to use, at which point it is optional to supply to the remaining methods.
Optional. If supplied, this prefix string is prepended to any key names passed in methods, and stripped from the response from list_bucket. It can be used to keep operations of the object contained within the named key space. If this string is supplied, don't forget that it should end with the path delimiter in use by the key naming scheme (for example /).
list_bucket
/
Optional. Maximum number of times to retry a failed operation. Defaults to 3.
Optional. Maximum number of keys at a time to request from S3 for the list_bucket method. Larger values may be more efficient as fewer roundtrips will be required per method call. Defaults to 1000.
Optional. Size in bytes to break content for using multipart upload. If an object key's size is no larger than this value, multipart upload will not be used. Defaults to 100 MiB.
Requests a list of the keys in a bucket, optionally within some prefix.
Takes the following named arguments:
The name of the S3 bucket to query
Optional. If supplied, the prefix and delimiter to use to divide up the key namespace. Keys will be divided on the delimiter parameter, and only the key space beginning with the given prefix will be queried.
delimiter
The Future will return two ARRAY references. The first provides a list of the keys found within the given prefix, and the second will return a list of the common prefixes of further nested keys.
( $keys, $prefixes ) = $f->get
Each key in the $keys list is given in a HASH reference containing
$keys
The key's name
The last modification time of the key given in ISO 8601 format
The entity tag of the key
The size of the key's value, in bytes
The S3 storage class of the key
Each key in the $prefixes list is given as a plain string.
$prefixes
Requests the value of a key from a bucket.
The name of the key to query
Optional. If supplied, this code will be invoked repeatedly on receipt of more bytes of the key's value. It will be passed an HTTP::Response object containing the key's metadata, and a byte string containing more bytes of the value. Its return value is not important.
$on_chunk->( $header, $bytes )
If this is supplied then the key's value will not be accumulated, and the final result of the Future will be an empty string.
The Future will return a byte string containing the key's value and the HTTP::Response containing the key's metadata.
( $value, $response ) = $f->get;
If an on_chunk code reference is passed, this string will be empty.
on_chunk
Sets a new value for a key in the bucket.
The name of the S3 bucket to put the value in
The name of the key to put the value in
Optional. If provided, gives a byte string as the new value for the key
Alternative to value in the case of larger values. Called repeatedly to generate successive chunks of the value. Each invocation will be passed a byte position and length, and should return a string of bytes.
value
$bytes = $gen_value->( $pos, $length )
This callback will not be invoked on a range outside of the length given by the value_length parameter. It may return a shorter byte chunk than requested.
value_length
If gen_value is given instead of value, this argument must be provided and gives the length of the data that gen_value will eventually generate.
gen_value
The Future will return a single string containing the S3 ETag of the newly-set key. For single-part uploads this will be the MD5 sum in hex, surrounded by quote marks. For multi-part uploads this is a string in a different form, though details of its generation are not specified by S3.
( $etag ) = $f->get
The returned MD5 sum from S3 during upload will be checked against an internally-generated MD5 sum of the content that was sent, and an error result will be returned if these do not match.
Deletes a key from the bucket.
The Future will return nothing.
Parts of this code were paid for by
Socialflow http://www.socialflow.com
Shadowcat Systems http://www.shadow.cat
Paul Evans <leonerd@leonerd.org.uk>
To install Net::Async::Webservice::S3, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::Webservice::S3
CPAN shell
perl -MCPAN -e shell install Net::Async::Webservice::S3
For more information on module installation, please visit the detailed CPAN module installation guide.