Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Add fog_options to configuration that can be passed to the fog #creat…
Browse files Browse the repository at this point in the history
…e method to configure multipart_chunk_size
  • Loading branch information
jeremywadsack committed Mar 23, 2016
1 parent 175c91a commit 7c153c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Improvement: Add `fog_options` configuration to send options to fog when storing files.

4.3.6 (3/13/2016):

* Bug Fix: When a spoofed media type is detected, megabytes of mime-types info are added to logs. See https://cwe.mitre.org/data/definitions/779.html.
Expand Down
10 changes: 8 additions & 2 deletions lib/paperclip/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/paperclip/storage/fog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c153c7

Please sign in to comment.