diff --git a/NEWS b/NEWS index c50a24e49..4d82a3333 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ master: +* Improvement: Add `fog_options` configuration to send options to fog when + storing files. * Drops support to end-of-life'd ruby 2.0. * Improvement: Paperclip now supports aws-sdk v2 @betesh, @davetchen, diff --git a/lib/paperclip/storage/fog.rb b/lib/paperclip/storage/fog.rb index 7b7f26515..8d0ed16a0 100644 --- a/lib/paperclip/storage/fog.rb +++ b/lib/paperclip/storage/fog.rb @@ -33,6 +33,10 @@ module Storage # that is the alias to the S3 domain of your bucket, e.g. # 'http://images.example.com'. This can also be used in # conjunction with Cloudfront (http://aws.amazon.com/cloudfront) + # * +fog_options+: (optional) A hash of options that are passed + # to fog when the file is created. For example, you could set + # the multipart-chunk size to 100MB with a hash: + # { :multipart_chunk_size => 104857600 } module Fog def self.extended base @@ -98,12 +102,14 @@ def flush_writes log("saving #{path(style)}") retried = false begin - directory.files.create(fog_file.merge( + attributes = fog_file.merge( :body => file, :key => path(style), :public => fog_public(style), :content_type => file.content_type - )) + ) + attributes.merge!(@options[:fog_options]) if @options[:fog_options] + directory.files.create(attributes) rescue Excon::Errors::NotFound raise if retried retried = true diff --git a/spec/paperclip/storage/fog_spec.rb b/spec/paperclip/storage/fog_spec.rb index bfaeea605..a48db202e 100644 --- a/spec/paperclip/storage/fog_spec.rb +++ b/spec/paperclip/storage/fog_spec.rb @@ -484,6 +484,25 @@ def custom_method assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials end end + + context "with custom fog_options" do + before do + rebuild_model( + @options.merge(fog_options: { multipart_chunk_size: 104857600 }), + ) + @dummy = Dummy.new + @dummy.avatar = @file + end + + it "applies the options to the fog #create call" do + files = stub + @dummy.avatar.stubs(:directory).returns stub(files: files) + files.expects(:create).with( + has_entries(multipart_chunk_size: 104857600), + ) + @dummy.save + end + end end end