Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send fog_attributes in Storage::Fog#copy_to #2504

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def filename(options = {})
# @return [CarrierWave::Storage::Fog::File] the location where the file will be stored.
#
def copy_to(new_path)
connection.copy_object(@uploader.fog_directory, file.key, @uploader.fog_directory, new_path, acl_header)
connection.copy_object(@uploader.fog_directory, file.key, @uploader.fog_directory, new_path, copy_to_options)
CarrierWave::Storage::Fog::File.new(@uploader, @base, new_path)
end

Expand Down Expand Up @@ -491,7 +491,15 @@ def directory
# [Fog::#{provider}::File] file data from remote service
#
def file
@file ||= directory.files.head(path)
@file ||= directory.files.head(path, head_options)
end

def head_options
@uploader.fog_attributes
end

def copy_to_options
acl_header.merge(@uploader.fog_attributes)
end

def acl_header
Expand Down
28 changes: 28 additions & 0 deletions spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,34 @@ def check_file
end
end

context '#uploader_options' do
let(:store_path) { 'uploads/test+.jpg' }
let(:fog_attributes) { { 'x-amz-server-side-encryption' => true } }

before do
allow(@uploader).to receive(:store_path).and_return(store_path)

if @provider == 'AWS'
allow(@uploader).to receive(:fog_attributes).and_return(fog_attributes)
end
end

it 'includes custom attributes' do
if file.is_a?(CarrierWave::Storage::Fog::File)
if @provider == 'AWS'
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything,
{ "x-amz-acl"=>"public-read", 'x-amz-server-side-encryption' => true }).and_call_original
else
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, {}).and_call_original
end

@storage.store!(file)
end
end
end

context '#acl_header' do
let(:store_path) { 'uploads/test+.jpg' }

Expand Down