mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|storage] Pull out body size calculations
This commit is contained in:
parent
e6a4085342
commit
e0b228c4ce
2 changed files with 13 additions and 1 deletions
|
@ -58,6 +58,16 @@ module Fog
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def 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 parse_data(data)
|
def parse_data(data)
|
||||||
metadata = {
|
metadata = {
|
||||||
:body => nil,
|
:body => nil,
|
||||||
|
@ -65,7 +75,7 @@ module Fog
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata[:body] = data
|
metadata[:body] = data
|
||||||
metadata[:headers]['Content-Length'] = data.size
|
metadata[:headers]['Content-Length'] = get_body_size(data)
|
||||||
|
|
||||||
if data.respond_to?(:path)
|
if data.respond_to?(:path)
|
||||||
filename = ::File.basename(data.path)
|
filename = ::File.basename(data.path)
|
||||||
|
|
|
@ -117,7 +117,9 @@ 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')
|
||||||
merge_attributes(data.headers)
|
merge_attributes(data.headers)
|
||||||
|
self.content_length = connection.get_body_size(body)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue