1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge remote branch 'origin/tumeric-v0.6.0.0' into tumeric-v0.7.0.0

Conflicts:
	lib/fog/storage/aws.rb
This commit is contained in:
Peter Weldon 2011-03-18 20:12:55 +00:00
commit f5f0a2f175
3 changed files with 27 additions and 14 deletions

View file

@ -21,26 +21,34 @@ module Fog
end
end
def self.get_body_size(body)
case
when body.respond_to?(:bytesize) then body.bytesize
when body.respond_to?(:size) then body.size
when body.respond_to?(:stat) then body.stat.size
else
0
end
end
def self.parse_data(data)
metadata = {
:body => nil,
:headers => {}
}
if data.is_a?(String)
metadata[:body] = data
metadata[:headers]['Content-Length'] = metadata[:body].size
else
metadata[:body] = data
metadata[:headers]['Content-Length'] = get_body_size(data)
if data.respond_to?(:path)
filename = ::File.basename(data.path)
unless (mime_types = MIME::Types.of(filename)).empty?
metadata[:headers]['Content-Type'] = mime_types.first.content_type
end
metadata[:body] = data
metadata[:headers]['Content-Length'] = ::File.size(data.path)
end
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
metadata
end
end
end
end

View file

@ -117,12 +117,10 @@ module Fog
options['x-amz-storage-class'] = storage_class if storage_class
data = connection.put_object(directory.key, key, body, options)
data.headers.delete('Content-Length')
data.headers['ETag'].gsub!('"','')
merge_attributes(data.headers)
if body.is_a?(String)
self.content_length = body.size
else
self.content_length = ::File.size(body.path)
end
self.content_length = Fog::Storage.get_body_size(body)
true
end

View file

@ -46,6 +46,7 @@ module Fog
:body => data.body,
:key => key
})
normalise_headers(file_data)
new(file_data)
rescue Excon::Errors::NotFound
nil
@ -62,6 +63,7 @@ module Fog
file_data = data.headers.merge({
:key => key
})
normalise_headers(file_data)
new(file_data)
rescue Excon::Errors::NotFound
nil
@ -72,6 +74,11 @@ module Fog
super({ :directory => directory }.merge!(attributes))
end
def normalise_headers(headers)
headers['Last-Modified'] = Time.parse(headers['Last-Modified'])
headers['ETag'].gsub!('"','')
end
end
end