diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index e947c628f..904511cdd 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -137,6 +137,9 @@ def self.extended(base) @s3_headers = {} merge_s3_headers(@options[:s3_headers], @s3_headers, @s3_metadata) + @s3_acl_enabled = @options[:s3_acl_enabled] + @s3_acl_enabled = true if @s3_acl_enabled.nil? + @s3_storage_class = set_storage_class(@options[:s3_storage_class]) @s3_server_side_encryption = "AES256" @@ -359,9 +362,12 @@ def flush_writes #:nodoc: log("saving #{path(style)}") write_options = { content_type: file.content_type, - acl: s3_permissions(style) } + if @s3_acl_enabled + write_options[:acl] = s3_permissions(style) + end + # add storage class for this style if defined storage_class = s3_storage_class(style) write_options.merge!(storage_class: storage_class) if storage_class diff --git a/spec/paperclip/storage/s3_spec.rb b/spec/paperclip/storage/s3_spec.rb index 47632ea51..5e497f105 100644 --- a/spec/paperclip/storage/s3_spec.rb +++ b/spec/paperclip/storage/s3_spec.rb @@ -411,6 +411,62 @@ def counter end end + context "An attachment that uses S3 for storage with acl disabled" do + before do + rebuild_model( + aws2_add_region.merge( + storage: :s3, + styles: { thumb: ["90x90#", :jpg] }, + bucket: "bucket", + s3_acl_enabled: false, + s3_credentials: { + "access_key_id" => "12345", + "secret_access_key" => "54321" + } + ) + ) + + @file = File.new(fixture_file("5k.png"), "rb") + @dummy = Dummy.new + @dummy.avatar = @file + @dummy.save + end + + context "reprocess" do + before do + @object = double + allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(@object) + allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(@object) + allow(@object).to receive(:get).and_yield(@file.read) + allow(@object).to receive(:exists?).and_return(true) + allow(@object).to receive(:download_file).with(anything) + end + + it "uploads original" do + expect(@object).to receive(:upload_file).with( + anything, + content_type: "image/png", + ).and_return(true) + @dummy.avatar.reprocess! + expect(@object).to receive(:upload_file).with( + anything, + content_type: "image/png", + ).and_return(true) + @dummy.avatar.reprocess! + end + + it "doesn't upload original" do + expect(@object).to receive(:upload_file).with( + anything, + content_type: "image/png", + ).and_return(true) + @dummy.avatar.reprocess! + end + end + + after { @file.close } + end + context "An attachment that uses S3 for storage and has styles" do before do rebuild_model(