diff --git a/lib/fog/storage.rb b/lib/fog/storage.rb index 0ea490ae8..f29fcf9b6 100644 --- a/lib/fog/storage.rb +++ b/lib/fog/storage.rb @@ -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 diff --git a/lib/fog/storage/models/aws/file.rb b/lib/fog/storage/models/aws/file.rb index 463e08497..da1a94eac 100644 --- a/lib/fog/storage/models/aws/file.rb +++ b/lib/fog/storage/models/aws/file.rb @@ -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) diff --git a/lib/fog/storage/models/google/file.rb b/lib/fog/storage/models/google/file.rb index 5f8967560..1883909f1 100644 --- a/lib/fog/storage/models/google/file.rb +++ b/lib/fog/storage/models/google/file.rb @@ -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 diff --git a/lib/fog/storage/models/local/file.rb b/lib/fog/storage/models/local/file.rb index bec3d1160..7e4da99a9 100644 --- a/lib/fog/storage/models/local/file.rb +++ b/lib/fog/storage/models/local/file.rb @@ -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 diff --git a/lib/fog/storage/models/rackspace/file.rb b/lib/fog/storage/models/rackspace/file.rb index 11c8dfcd9..4ffbf0543 100644 --- a/lib/fog/storage/models/rackspace/file.rb +++ b/lib/fog/storage/models/rackspace/file.rb @@ -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