Skip to content

Commit

Permalink
GCS: pass acl_header for public read if fog is public
Browse files Browse the repository at this point in the history
If not done, uploading a file via carrierwave with fog_public will return access denied.

Closes carrierwaveuploader#2426
  • Loading branch information
yosiat authored and joemsak committed Mar 27, 2021
1 parent 9495178 commit bba8b0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ def uploader_options
def acl_header
if fog_provider == 'AWS'
{ 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' }
elsif fog_provider == "Google"
@uploader.fog_public ? { destination_predefined_acl: "publicRead" } : {}
else
{}
end
Expand Down
5 changes: 4 additions & 1 deletion spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def check_file
if file.is_a?(CarrierWave::Storage::Fog::File)
if @provider == 'AWS'
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, { "Content-Type"=>file.content_type, "x-amz-acl"=>"public-read" }).and_call_original
.with(anything, anything, anything, anything, { "x-amz-acl"=>"public-read" }).and_call_original
elsif @provider == 'Google'
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, { destination_predefined_acl: "publicRead" }).and_call_original
else
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, { "Content-Type"=>file.content_type }).and_call_original
Expand Down

0 comments on commit bba8b0f

Please # to comment.