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
|
||||||
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)
|
def self.parse_data(data)
|
||||||
metadata = {
|
metadata = {
|
||||||
:body => nil,
|
:body => nil,
|
||||||
:headers => {}
|
:headers => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.is_a?(String)
|
metadata[:body] = data
|
||||||
metadata[:body] = data
|
metadata[:headers]['Content-Length'] = get_body_size(data)
|
||||||
metadata[:headers]['Content-Length'] = metadata[:body].size
|
|
||||||
else
|
if data.respond_to?(:path)
|
||||||
filename = ::File.basename(data.path)
|
filename = ::File.basename(data.path)
|
||||||
unless (mime_types = MIME::Types.of(filename)).empty?
|
unless (mime_types = MIME::Types.of(filename)).empty?
|
||||||
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
||||||
end
|
end
|
||||||
metadata[:body] = data
|
|
||||||
metadata[:headers]['Content-Length'] = ::File.size(data.path)
|
|
||||||
end
|
end
|
||||||
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
||||||
metadata
|
metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -117,12 +117,10 @@ module Fog
|
||||||
options['x-amz-storage-class'] = storage_class if storage_class
|
options['x-amz-storage-class'] = storage_class if storage_class
|
||||||
|
|
||||||
data = connection.put_object(directory.key, key, body, options)
|
data = connection.put_object(directory.key, key, body, options)
|
||||||
|
data.headers.delete('Content-Length')
|
||||||
|
data.headers['ETag'].gsub!('"','')
|
||||||
merge_attributes(data.headers)
|
merge_attributes(data.headers)
|
||||||
if body.is_a?(String)
|
self.content_length = Fog::Storage.get_body_size(body)
|
||||||
self.content_length = body.size
|
|
||||||
else
|
|
||||||
self.content_length = ::File.size(body.path)
|
|
||||||
end
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ module Fog
|
||||||
:body => data.body,
|
:body => data.body,
|
||||||
:key => key
|
:key => key
|
||||||
})
|
})
|
||||||
|
normalise_headers(file_data)
|
||||||
new(file_data)
|
new(file_data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
|
@ -62,6 +63,7 @@ module Fog
|
||||||
file_data = data.headers.merge({
|
file_data = data.headers.merge({
|
||||||
:key => key
|
:key => key
|
||||||
})
|
})
|
||||||
|
normalise_headers(file_data)
|
||||||
new(file_data)
|
new(file_data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
|
@ -72,6 +74,11 @@ module Fog
|
||||||
super({ :directory => directory }.merge!(attributes))
|
super({ :directory => directory }.merge!(attributes))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def normalise_headers(headers)
|
||||||
|
headers['Last-Modified'] = Time.parse(headers['Last-Modified'])
|
||||||
|
headers['ETag'].gsub!('"','')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue