| Class | Net::Amazon::S3 |
| In: |
lib/net/amazon/s3.rb
lib/net/amazon/s3/bucket.rb lib/net/amazon/s3/errors.rb lib/net/amazon/s3/object.rb |
| Parent: | Object |
This library implements the Amazon S3 REST API (Rubyfied for your pleasure). Its usage is hopefully pretty straightforward. See below for examples.
| Author: | Ryan Grove (ryan@wonko.com) |
| Version: | 0.1.0 |
| Copyright: | Copyright (c) 2006 Ryan Grove. All rights reserved. |
| License: | New BSD License (opensource.org/licenses/bsd-license.php) |
| Website: | wonko.com/software/net-amazon-s3 |
Amazon S3 stores arbitrary values (objects) identified by keys and organized into buckets. An S3 bucket is essentially a glorified Hash. Object values can be up to 5 GB in size, and objects can also have up to 2 KB of metadata associated with them.
Bucket names share a global namespace and must be unique across all of S3, but object keys only have to be unique within the bucket in which they are stored.
For more details, visit s3.amazonaws.com
gem install net-amazon-s3
require 'rubygems' require 'net/amazon/s3' access_key_id = 'DXM37ARQ25519H34E6W2' secret_access_key = '43HM88c+8kYr/UeFp+shjTnzFgisO5AZzpEO06FU' s3 = Net::Amazon::S3.new(access_key_id, secret_access_key)
foo = s3.create_bucket('foo')
foo['bar'] = 'baz' # create object 'bar' and assign it the
# value 'baz'
File.open('mybigmovie.avi', 'rb') do |file|
foo['mybigmovie.avi'] = file
end
File.open('mybigmovie.avi', 'wb') do |file|
foo['mybigmovie.avi'].value {|chunk| file.write(chunk) }
end
objects = foo.get_objects
my_objects = foo.get_objects('my')
s3.delete_bucket('foo', true)
| REST_ENDPOINT | = | 's3.amazonaws.com' |
| access_key_id | [RW] | |
| options | [R] | |
| secret_access_key | [RW] |
Creates and returns a new S3 client. The following options are available:
Returns true if a bucket with the specified bucket_name exists in this S3 account, false otherwise.
Deletes the bucket with the specified bucket_name. If recursive is true, all objects contained in the bucket will also be deleted. If recursive is false and the bucket is not empty, a S3Error::BucketNotEmpty error will be raised.
Returns a Bucket object representing the specified bucket, or nil if the bucket doesn‘t exist.
Gets a list of all buckets owned by this account. Returns a Hash of Bucket objects indexed by bucket name.
Sends a properly-signed DELETE request to the specified S3 path and returns a Net::HTTPResponse object.
Sends a properly-signed GET request to the specified S3 path and returns a Net::HTTPResponse object.
When called with a block, yields a Net::HTTPResponse object whose body has not been read; the caller can process it using Net::HTTPResponse.read_body.
Sends a properly-signed HEAD request to the specified S3 path and returns a Net::HTTPResponse object.
Sends a properly-signed PUT request to the specified S3 path and returns a Net::HTTPResponse object.
If content is an open IO stream, the body of the request will be read from the stream.