include the content type when uploading to S3

This commit is contained in:
Simo Leone 2019-01-24 16:56:24 +00:00
parent 1fecebae31
commit c5b71c9bae
No known key found for this signature in database
GPG Key ID: 879B8C9843368178
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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"