Set Content-Type on variant uploads

This commit is contained in:
Kyle Ribordy 2019-09-16 21:08:22 -07:00 committed by George Claghorn
parent 60d3c14a73
commit 698e9ce0ff
3 changed files with 17 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* The `Content-Type` header is set on image variants when they're uploaded to third-party storage services.
*Kyle Ribordy*
* Allow storage services to be configured per attachment
```ruby

View File

@ -98,7 +98,7 @@ class ActiveStorage::Variant
def process
blob.open do |input|
variation.transform(input, format: format) do |output|
service.upload(key, output)
service.upload(key, output, content_type: content_type)
end
end
end

View File

@ -196,4 +196,16 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
ensure
ActiveStorage.variant_processor = :mini_magick
end
test "passes content_type on upload" do
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
mock_upload = lambda do |_, _, options = {}|
assert_equal options[:content_type], "image/jpeg"
end
blob.service.stub(:upload, mock_upload) do
blob.variant(resize: "100x100").processed
end
end
end