aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2019-02-01 09:37:08 -0500
committerGitHub <noreply@github.com>2019-02-01 09:37:08 -0500
commit300c62f75cc1b48fe5152717f395ee8d94c1ceaf (patch)
treec425fd4839dd35b1b44f9769db174852083ce51d /activestorage
parent79bc9e81c3d47be6336223be39cb3bcaeddc0a39 (diff)
parentc5b71c9baea4959c096774c763e558df2979a9db (diff)
downloadrails-300c62f75cc1b48fe5152717f395ee8d94c1ceaf.tar.gz
rails-300c62f75cc1b48fe5152717f395ee8d94c1ceaf.tar.bz2
rails-300c62f75cc1b48fe5152717f395ee8d94c1ceaf.zip
Merge pull request #35043 from simoleone/activestorage/s3/content-type
include the content type when uploading to S3
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/lib/active_storage/service/s3_service.rb4
-rw-r--r--activestorage/test/service/s3_service_test.rb18
2 files changed, 20 insertions, 2 deletions
diff --git a/activestorage/lib/active_storage/service/s3_service.rb b/activestorage/lib/active_storage/service/s3_service.rb
index 382920ef61..bf94f3f49e 100644
--- a/activestorage/lib/active_storage/service/s3_service.rb
+++ b/activestorage/lib/active_storage/service/s3_service.rb
@@ -16,9 +16,9 @@ module ActiveStorage
@upload_options = upload
end
- def upload(key, io, checksum: nil, **)
+ def upload(key, io, checksum: nil, content_type: nil, **)
instrument :upload, key: key, checksum: checksum do
- object_for(key).put(upload_options.merge(body: io, content_md5: checksum))
+ object_for(key).put(upload_options.merge(body: io, content_md5: checksum, content_type: content_type))
rescue Aws::S3::Errors::BadDigest
raise ActiveStorage::IntegrityError
end
diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb
index 0a6004267f..74c0aa0405 100644
--- a/activestorage/test/service/s3_service_test.rb
+++ b/activestorage/test/service/s3_service_test.rb
@@ -59,6 +59,24 @@ if SERVICE_CONFIGURATIONS[:s3]
service.delete key
end
end
+
+ test "upload with content type" do
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ content_type = "text/plain"
+
+ @service.upload(
+ key,
+ StringIO.new(data),
+ checksum: Digest::MD5.base64digest(data),
+ filename: "cool_data.txt",
+ content_type: content_type
+ )
+
+ assert_equal content_type, @service.bucket.object(key).content_type
+ ensure
+ @service.delete key
+ end
end
else
puts "Skipping S3 Service tests because no S3 configuration was supplied"