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

[storage] fix/consolidate content-length for utf8

closes #327
This commit is contained in:
geemus 2011-05-25 14:37:47 -07:00
parent db42fae89a
commit 597acf0363
5 changed files with 9 additions and 16 deletions

View file

@ -22,12 +22,14 @@ module Fog
end
def self.get_body_size(body)
case
when body.respond_to?(:bytesize)
if body.respond_to?(:force_encoding)
body.force_encoding('BINARY')
end
if body.respond_to?(:bytesize)
body.bytesize
when body.respond_to?(:size)
elsif body.respond_to?(:size)
body.size
when body.respond_to?(:stat)
elsif body.respond_to?(:stat)
body.stat.size
else
0

View file

@ -117,7 +117,6 @@ 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)
self.content_length = Fog::Storage.get_body_size(body)

View file

@ -119,11 +119,7 @@ module Fog
data = connection.put_object(directory.key, key, body, options)
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

@ -88,7 +88,7 @@ module Fog
end
file.close
merge_attributes(
:content_length => ::File.size(path),
:content_length => Fog::Storage.get_body_size(body),
:last_modified => ::File.mtime(path)
)
true

View file

@ -60,11 +60,7 @@ module Fog
options['Content-Type'] = content_type if content_type
data = connection.put_object(directory.key, key, body, options)
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