mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'Lautus'
This commit is contained in:
commit
9751fc418f
3 changed files with 30 additions and 14 deletions
|
@ -21,26 +21,37 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def self.get_body_size(body)
|
||||
case
|
||||
when body.respond_to?(:bytesize)
|
||||
body.bytesize
|
||||
when body.respond_to?(:size)
|
||||
body.size
|
||||
when body.respond_to?(:stat)
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue