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:
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')
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.
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.
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.
@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]