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

CarrierWave::Storage::Fog#copy_to with Content-Type header #2503

Merged
merged 4 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ 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)
options = {}
options.merge!(acl_header) if acl_header.present?
options['Content-Type'] ||= content_type if content_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also saw that we're missing @uploader.fog_attributes. I think we should break this into a separate method? (#2504)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, merged

connection.copy_object(@uploader.fog_directory, file.key, @uploader.fog_directory, new_path, options)
CarrierWave::Storage::Fog::File.new(@uploader, @base, new_path)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,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, { "x-amz-acl"=>"public-read" }).and_call_original
.with(anything, anything, anything, anything, { "Content-Type"=>file.content_type, "x-amz-acl"=>"public-read" }).and_call_original
else
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, {}).and_call_original
.with(anything, anything, anything, anything, { "Content-Type"=>file.content_type }).and_call_original
end
end

Expand Down