diff --git a/lib/fog/aws/models/storage/file.rb b/lib/fog/aws/models/storage/file.rb index 4dae684a9..6c5f9971b 100644 --- a/lib/fog/aws/models/storage/file.rb +++ b/lib/fog/aws/models/storage/file.rb @@ -27,7 +27,11 @@ module Fog # @note Chunk size to use for multipart uploads. # Use small chunk sizes to minimize memory. E.g. 5242880 = 5mb - attr_accessor :multipart_chunk_size + attr_reader :multipart_chunk_size + def multipart_chunk_size=(mp_chunk_size) + raise ArgumentError.new("minimum multipart_chunk_size is 5242880") if mp_chunk_size < 5242880 + @multipart_chunk_size = mp_chunk_size + end def acl requires :directory, :key @@ -205,7 +209,10 @@ module Fog options['x-amz-storage-class'] = storage_class if storage_class options.merge!(encryption_headers) - if multipart_chunk_size && body.respond_to?(:read) + # With a single PUT operation you can upload objects up to 5 GB in size. Automatically set MP for larger objects. + multipart_chunk_size=5242880 if !multipart_chunk_size && Fog::Storage.get_body_size(body) > 5368709120 + + if multipart_chunk_size && Fog::Storage.get_body_size(body) >= multipart_chunk_size && body.respond_to?(:read) data = multipart_save(options) merge_attributes(data.body) else