class AWS::S3::ObjectMetadata
Returns an object that represents the metadata for an S3 object.
Attributes
@return [S3Object]
Public Class Methods
@param [S3Object] object @param [Hash] options @option options [String] :version_id A specific version of the object
to get metadata for
# File lib/aws/s3/object_metadata.rb, line 26 def initialize object, options = {} @object = object @version_id = options[:version_id] super end
Public Instance Methods
Returns the value for the given name stored in the S3Object's metadata:
bucket.objects['myobject'].metadata['purpose'] # returns nil if the given metadata key has not been set
@param [String,Symbol] name The name of the metadata field to
get.
@return [String,nil] Returns the metadata for the given name.
# File lib/aws/s3/object_metadata.rb, line 45 def [] name to_h[name.to_s] end
Changes the value of the given name stored in the S3Object's metadata:
object = bucket.object['myobject'] object.metadata['purpose'] = 'research' object.metadata['purpose'] # => 'research'
@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.
@note The name and value of each metadata field must conform
to US-ASCII.
@param [String,Symbol] name The name of the metadata field to
set.
@param [String] value The new value of the metadata field.
@return [String,nil] Returns the value that was set.
# 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 metadata = to_h.dup metadata[name.to_s] = value object.copy_from(object.key, :metadata => metadata) value end
Proxies the method to {#[]}. @return (see [])
# File lib/aws/s3/object_metadata.rb, line 85 def method_missing name, *args, &blk return super if !args.empty? || blk self[name] end
@return [Hash] Returns the user-generated metadata stored with
this S3 Object.
# File lib/aws/s3/object_metadata.rb, line 92 def to_h options = {} options[:bucket_name] = object.bucket.name options[:key] = object.key options[:version_id] = @version_id if @version_id client.head_object(options).meta end