Skip to content

Commit

Permalink
Added the methods Key#content_type and Key#decoded_meta_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Fouché authored and Konstantin committed Mar 31, 2010
1 parent d201e2a commit 4dc7b46
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/s3/right_s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,30 @@ def data
get if !@data and exists?
@data
end

# Getter for the 'content-type' metadata
def content_type
@headers['content-type'] if @headers
end

# Helper to get and URI-decode a header metadata.
# Metadata have to be HTTP encoded (rfc2616) as we use the Amazon S3 REST api
# see http://docs.amazonwebservices.com/AmazonS3/latest/index.html?UsingMetadata.html
def decoded_meta_headers(key = nil)
if key
# Get one metadata value by its key
URI.decode(@meta_headers[key.to_s])
else
# Get a hash of all metadata with a decoded value
@decoded_meta_headers ||= begin
metadata = {}
@meta_headers.each do |key, value|
metadata[key.to_sym] = URI.decode(value)
end
metadata
end
end
end

# Retrieve object data and attributes from Amazon.
# Returns a +String+.
Expand Down

0 comments on commit 4dc7b46

Please sign in to comment.