You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.
Class: AWS::S3::ObjectMetadata
- Inherits:
-
Object
- Object
- AWS::S3::ObjectMetadata
- Defined in:
- lib/aws/s3/object_metadata.rb
Overview
Returns an object that represents the metadata for an S3 object.
Instance Attribute Summary collapse
-
#object ⇒ S3Object
readonly
Instance Method Summary collapse
-
#[](name) ⇒ String?
Returns the value for the given name stored in the S3Object's metadata:.
-
#[]=(name, value) ⇒ String?
deprecated
Deprecated.
In order to safely update an S3 object's metadata, you should use S3Object#copy_from. This operation does not preserve the ACL, storage class (standard vs. reduced redundancy) or server side encryption settings. Using this method on anything other than vanilla S3 objects risks clobbering other metadata values set on the object.
-
#initialize(object, options = {}) ⇒ ObjectMetadata
constructor
A new instance of ObjectMetadata.
-
#method_missing(name, *args, &blk) ⇒ String?
Proxies the method to #[].
-
#to_h ⇒ Hash
Returns the user-generated metadata stored with this S3 Object.
Constructor Details
#initialize(object, options = {}) ⇒ ObjectMetadata
Returns a new instance of ObjectMetadata
26 27 28 29 30 |
# File 'lib/aws/s3/object_metadata.rb', line 26 def initialize object, = {} @object = object @version_id = [:version_id] super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ String?
Proxies the method to #[].
85 86 87 88 |
# File 'lib/aws/s3/object_metadata.rb', line 85 def method_missing name, *args, &blk return super if !args.empty? || blk self[name] end |
Instance Attribute Details
#object ⇒ S3Object (readonly)
33 34 35 |
# File 'lib/aws/s3/object_metadata.rb', line 33 def object @object end |
Instance Method Details
#[](name) ⇒ String?
Returns the value for the given name stored in the S3Object's metadata:
bucket.objects['myobject'].['purpose']
# returns nil if the given metadata key has not been set
45 46 47 |
# File 'lib/aws/s3/object_metadata.rb', line 45 def [] name to_h[name.to_s] end |
#[]=(name, value) ⇒ String?
In order to safely update an S3 object's metadata, you should use S3Object#copy_from. This operation does not preserve the ACL, storage class (standard vs. reduced redundancy) or server side encryption settings. Using this method on anything other than vanilla S3 objects risks clobbering other metadata values set on the object.
The name and value of each metadata field must conform to US-ASCII.
Changes the value of the given name stored in the S3Object's metadata:
object = bucket.object['myobject']
object.['purpose'] = 'research'
object.['purpose'] # => 'research'
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/aws/s3/object_metadata.rb', line 72 def []= name, value raise "cannot change the metadata of an object version; "+ "use S3Object#write to create a new version with different metadata" if @version_id = to_h.dup [name.to_s] = value object.copy_from(object.key, :metadata => ) value end |
#to_h ⇒ Hash
Returns the user-generated metadata stored with this S3 Object.
92 93 94 95 96 97 98 |
# File 'lib/aws/s3/object_metadata.rb', line 92 def to_h = {} [:bucket_name] = object.bucket.name [:key] = object.key [:version_id] = @version_id if @version_id client.head_object(). end |