Class: S3::Object
- Inherits:
-
Object
- Object
- S3::Object
- Extended by:
- Forwardable
- Includes:
- Parser
- Defined in:
- lib/s3/object.rb
Overview
Class responsible for handling objects stored in S3 buckets
Instance Attribute Summary (collapse)
-
- (Object) acl
Returns the value of attribute acl.
-
- (Object) bucket
readonly
Returns the value of attribute bucket.
-
- (Object) cache_control
Returns the value of attribute cache_control.
-
- (Object) content(reload = false)
Downloads the content of the object, and caches it.
-
- (Object) content_disposition
Returns the value of attribute content_disposition.
-
- (Object) content_encoding
Returns the value of attribute content_encoding.
-
- (Object) content_type
Returns the value of attribute content_type.
-
- (Object) etag
readonly
Returns the value of attribute etag.
-
- (Object) key
Returns the value of attribute key.
-
- (Object) last_modified
readonly
Returns the value of attribute last_modified.
-
- (Object) size
readonly
Returns the value of attribute size.
-
- (Object) storage_class
Returns the value of attribute storage_class.
Instance Method Summary (collapse)
-
- (Object) ==(other)
Compares the object with other object.
-
- (Object) cname_url
Returns Object's CNAME URL (without s3.amazonaws.com suffix) using protocol specified in Service, e.g.
-
- (Object) copy(options = {})
Copies the file to another key and/or bucket.
-
- (Object) destroy
Destroys the file on the server.
-
- (Boolean) exists?
Retrieves the object from the server, returns true if the object exists or false otherwise.
-
- (Object) full_key
Returns full key of the object: e.g.
-
- (Object) inspect
:nodoc:.
-
- (Object) retrieve
Retrieves the object from the server.
-
- (Object) save
Saves the object, returns true if successfull.
-
- (Object) temporary_url(expires_at = Time.now + 3600)
Returns a temporary url to the object that expires on the timestamp given.
-
- (Object) url
Returns Object's URL using protocol specified in service, e.g.
Methods included from Parser
#parse_copy_object_result, #parse_error, #parse_is_truncated, #parse_list_all_my_buckets_result, #parse_list_bucket_result, #parse_location_constraint, #rexml_document
Instance Attribute Details
- (Object) acl
Returns the value of attribute acl
9 10 11 |
# File 'lib/s3/object.rb', line 9 def acl @acl end |
- (Object) bucket
Returns the value of attribute bucket
9 10 11 |
# File 'lib/s3/object.rb', line 9 def bucket @bucket end |
- (Object) cache_control
Returns the value of attribute cache_control
8 9 10 |
# File 'lib/s3/object.rb', line 8 def cache_control @cache_control end |
- (Object) content(reload = false)
Downloads the content of the object, and caches it. Pass true to clear the cache and download the object again.
75 76 77 78 79 |
# File 'lib/s3/object.rb', line 75 def content(reload = false) return @content if defined?(@content) and not reload get_object @content end |
- (Object) content_disposition
Returns the value of attribute content_disposition
8 9 10 |
# File 'lib/s3/object.rb', line 8 def content_disposition @content_disposition end |
- (Object) content_encoding
Returns the value of attribute content_encoding
8 9 10 |
# File 'lib/s3/object.rb', line 8 def content_encoding @content_encoding end |
- (Object) content_type
Returns the value of attribute content_type
8 9 10 |
# File 'lib/s3/object.rb', line 8 def content_type @content_type end |
- (Object) etag
Returns the value of attribute etag
9 10 11 |
# File 'lib/s3/object.rb', line 9 def etag @etag end |
- (Object) key
Returns the value of attribute key
9 10 11 |
# File 'lib/s3/object.rb', line 9 def key @key end |
- (Object) last_modified
Returns the value of attribute last_modified
9 10 11 |
# File 'lib/s3/object.rb', line 9 def last_modified @last_modified end |
- (Object) size
Returns the value of attribute size
9 10 11 |
# File 'lib/s3/object.rb', line 9 def size @size end |
- (Object) storage_class
Returns the value of attribute storage_class
9 10 11 |
# File 'lib/s3/object.rb', line 9 def storage_class @storage_class end |
Instance Method Details
- (Object) ==(other)
Compares the object with other object. Returns true if the key of the objects are the same, and both have the same buckets (see Bucket equality)
19 20 21 |
# File 'lib/s3/object.rb', line 19 def ==(other) other.equal?(self) || (other.instance_of?(self.class) && self.key == other.key && self.bucket == other.bucket) end |
- (Object) cname_url
Returns Object's CNAME URL (without s3.amazonaws.com suffix) using protocol specified in Service, e.g. http://domain.com/key/with/path.extension. (you have to set the CNAME in your DNS before using the CNAME URL schema).
129 130 131 |
# File 'lib/s3/object.rb', line 129 def cname_url URI.escape("#{protocol}#{name}/#{key}") if bucket.vhost? end |
- (Object) copy(options = {})
Copies the file to another key and/or bucket.
Options
-
:key - New key to store object in
-
:bucket - New bucket to store object in (instance of S3::Bucket)
-
:acl - ACL of the copied object (default: ???public-read???)
-
:content_type - Content type of the copied object (default: ???application/octet-stream???)
97 98 99 |
# File 'lib/s3/object.rb', line 97 def copy( = {}) copy_object() end |
- (Object) destroy
Destroys the file on the server
102 103 104 105 |
# File 'lib/s3/object.rb', line 102 def destroy delete_object true end |
- (Boolean) exists?
Retrieves the object from the server, returns true if the object exists or false otherwise. Uses #retrieve method, but catches S3::Error::NoSuchKey exception and returns false when it happens
66 67 68 69 70 71 |
# File 'lib/s3/object.rb', line 66 def exists? retrieve true rescue Error::NoSuchKey false end |
- (Object) full_key
Returns full key of the object: e.g. bucket-name/object/key.ext
24 25 26 |
# File 'lib/s3/object.rb', line 24 def full_key [name, key].join("/") end |
- (Object) inspect
:nodoc:
133 134 135 |
# File 'lib/s3/object.rb', line 133 def inspect #:nodoc: "#<#{self.class}:/#{name}/#{key}>" end |
- (Object) retrieve
Retrieves the object from the server. Method is used to download object information only (content type, size and so on). It does NOT download the content of the object (use the #content method to do it).
58 59 60 61 |
# File 'lib/s3/object.rb', line 58 def retrieve object_headers self end |
- (Object) save
Saves the object, returns true if successfull.
82 83 84 85 |
# File 'lib/s3/object.rb', line 82 def save put_object true end |
- (Object) temporary_url(expires_at = Time.now + 3600)
Returns a temporary url to the object that expires on the timestamp given. Defaults to one hour expire time.
115 116 117 118 119 120 121 122 |
# File 'lib/s3/object.rb', line 115 def temporary_url(expires_at = Time.now + 3600) signature = Signature.generate_temporary_url_signature(:bucket => name, :resource => key, :expires_at => expires_at, :secret_access_key => secret_access_key) "#{url}?AWSAccessKeyId=#{self.bucket.service.access_key_id}&Expires=#{expires_at.to_i.to_s}&Signature=#{signature}" end |
- (Object) url
Returns Object's URL using protocol specified in service, e.g. http://domain.com.s3.amazonaws.com/key/with/path.extension
109 110 111 |
# File 'lib/s3/object.rb', line 109 def url URI.escape("#{protocol}#{host}/#{path_prefix}#{key}") end |