Class AWS::S3
In: lib/aws/s3/request.rb
lib/aws/s3/prefixed_collection.rb
lib/aws/s3/object_collection.rb
lib/aws/s3/paginated_collection.rb
lib/aws/s3/s3_object.rb
lib/aws/s3/multipart_upload.rb
lib/aws/s3/presigned_post.rb
lib/aws/s3/uploaded_part.rb
lib/aws/s3/client.rb
lib/aws/s3/prefix_and_delimiter_collection.rb
lib/aws/s3/client/xml.rb
lib/aws/s3/tree.rb
lib/aws/s3/bucket_collection.rb
lib/aws/s3/policy.rb
lib/aws/s3/multipart_upload_collection.rb
lib/aws/s3/object_version.rb
lib/aws/s3/bucket.rb
lib/aws/s3/access_control_list.rb
lib/aws/s3/object_upload_collection.rb
lib/aws/s3/errors.rb
lib/aws/s3/tree/node.rb
lib/aws/s3/tree/child_collection.rb
lib/aws/s3/tree/branch_node.rb
lib/aws/s3/tree/leaf_node.rb
lib/aws/s3/tree/parent.rb
lib/aws/s3/uploaded_part_collection.rb
lib/aws/s3/data_options.rb
lib/aws/s3/bucket_version_collection.rb
lib/aws/s3/acl_object.rb
lib/aws/s3/object_metadata.rb
lib/aws/s3/object_version_collection.rb
lib/aws/s3.rb
Parent: Object

Provides an expressive, object-oriented interface to Amazon S3.

To use Amazon S3 you must first sign up here.

For more information about Amazon S3, see:

Credentials

You can setup default credentials for all AWS services via AWS.config:

  AWS.config(
    :access_key_id => 'YOUR_ACCESS_KEY_ID',
    :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')

Or you can set them directly on the S3 interface:

  s3 = AWS::S3.new(
    :access_key_id => 'YOUR_ACCESS_KEY_ID',
    :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')

Buckets Keys and Objects

S3 stores objects in buckets.

To create a bucket:

  bucket = s3.buckets.create('mybucket')

To get a bucket:

  bucket = s3.buckets[:mybucket]
  bucket = s3.buckets['mybucket']

Listing buckets:

  s3.buckets.each do |bucket|
    puts bucket.name
  end

See {Bucket} and {BucketCollection} for more information on working with S3 buckets.

Listing Objects

Enumerating objects in a bucket:

  bucket.objects.each do |object|
    puts object.key #=> no data is fetched from s3, just a list of keys
  end

You can limit the list of objects with a prefix, or explore the objects in a bucket as a tree. See {ObjectCollection} for more information.

Reading and Writing to S3

Each object in a bucket has a unique key.

  photo = s3.buckets['mybucket'].objects['photo.jpg']

Writing to an S3Object:

  photo.write(File.read('/some/photo.jpg'))

Reading from an S3Object:

  File.open("/some/path/on/disk.jpg", "w") do |f|
    f.write(photo.read)
  end

See {S3Object} for more information on reading and writing to S3.

Methods

Included Modules

ServiceInterface

Classes and Modules

Module AWS::S3::ACLObject
Module AWS::S3::DataOptions
Module AWS::S3::Errors
Module AWS::S3::PaginatedCollection
Module AWS::S3::PrefixAndDelimiterCollection
Module AWS::S3::PrefixedCollection
Class AWS::S3::AccessControlList
Class AWS::S3::Bucket
Class AWS::S3::BucketCollection
Class AWS::S3::BucketVersionCollection
Class AWS::S3::Client
Class AWS::S3::MultipartUpload
Class AWS::S3::MultipartUploadCollection
Class AWS::S3::ObjectCollection
Class AWS::S3::ObjectMetadata
Class AWS::S3::ObjectUploadCollection
Class AWS::S3::ObjectVersion
Class AWS::S3::ObjectVersionCollection
Class AWS::S3::Policy
Class AWS::S3::PresignedPost
Class AWS::S3::Request
Class AWS::S3::S3Object
Class AWS::S3::Tree
Class AWS::S3::UploadedPart
Class AWS::S3::UploadedPartCollection

Public Instance methods

@return [BucketCollection] Returns a collection that represents all

 buckets in the account.

Generates fields for a presigned POST to this object. This method adds a constraint that the key must match the key of this object. All options are sent to the PresignedPost constructor.

@see PresignedPost @return [PresignedPost]

Generates a public (not authenticated) URL for the object.

@param [Hash] options Options for generating the URL.

@option options [Boolean] :secure Whether to generate a

  secure (HTTPS) URL or a plain HTTP url.

@return [URI::HTTP, URI::HTTPS]

@note Changing the storage class of an object incurs a COPY

  operation.

Changes the storage class of the object to enable or disable Reduced Redundancy Storage (RRS).

@param [true,false] value If this is true, the object will be

  copied in place and stored with reduced redundancy at a
  lower cost.  Otherwise, the object will be copied and stored
  with the standard storage class.

@return [true,false] The value parameter.

Generates a presigned URL for an operation on this object. This URL can be used by a regular HTTP client to perform the desired operation without credentials and without changing the permissions of the object.

@example Generate a url to read an object

  bucket.objects.myobject.url_for(:read)

@example Generate a url to delete an object

  bucket.objects.myobject.url_for(:delete)

@example Override response headers for reading an object

  object = bucket.objects.myobject
  url = object.url_for(:read, :response_content_type => "application/json")

@example Generate a url that expires in 10 minutes

  bucket.objects.myobject.url_for(:read, :expires => 10*60)

@param [Symbol, String] method The HTTP verb or object

  method for which the returned URL will be valid.  Valid
  values:

  * +:get+ or +:read+
  * +:put+ or +:write+
  * +:delete+

@param [Hash] options Additional options for generating the URL.

@option options :expires Sets the expiration time of the

  URL; after this time S3 will return an error if the URL is
  used.  This can be an integer (to specify the number of
  seconds after the current time), a string (which is parsed
  as a date using Time#parse), a Time, or a DateTime object.
  This option defaults to one hour after the current time.

@option options [String] :secure Whether to generate a

  secure (HTTPS) URL or a plain HTTP url.

@option options [String] :response_content_type Sets the

  Content-Type header of the response when performing an
  HTTP GET on the returned URL.

@option options [String] :response_content_language Sets the

  Content-Language header of the response when performing an
  HTTP GET on the returned URL.

@option options [String] :response_expires Sets the Expires

  header of the response when performing an HTTP GET on the
  returned URL.

@option options [String] :response_cache_control Sets the

  Cache-Control header of the response when performing an
  HTTP GET on the returned URL.

@option options [String] :response_content_disposition Sets

  the Content-Disposition header of the response when
  performing an HTTP GET on the returned URL.

@option options [String] :response_content_encoding Sets the

  Content-Encoding header of the response when performing an
  HTTP GET on the returned URL.

@return [URI::HTTP, URI::HTTPS]

[Validate]