From 92a69def94ed11ae29052ce3129c53626b71e0fe Mon Sep 17 00:00:00 2001 From: Yosi Attias Date: Wed, 30 Dec 2020 16:39:49 +0200 Subject: [PATCH] GCS: pass acl_header for public read if fog is public If not done, uploading a file via carrierwave with fog_public will return access denied. Closes https://github.com/carrierwaveuploader/carrierwave/issues/2426 --- lib/carrierwave/storage/fog.rb | 2 ++ spec/storage/fog_helper.rb | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 8bc04ae93..128334289 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -497,6 +497,8 @@ def file 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 diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index 3a3622aa7..090a05a5b 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -69,6 +69,9 @@ def check_file if @provider == 'AWS' expect(@storage.connection).to receive(:copy_object) .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, {}).and_call_original