mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
include the content type when uploading to S3
This commit is contained in:
parent
1fecebae31
commit
c5b71c9bae
2 changed files with 20 additions and 2 deletions
|
@ -16,9 +16,9 @@ module ActiveStorage
|
||||||
@upload_options = upload
|
@upload_options = upload
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(key, io, checksum: nil, **)
|
def upload(key, io, checksum: nil, content_type: nil, **)
|
||||||
instrument :upload, key: key, checksum: checksum do
|
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
|
rescue Aws::S3::Errors::BadDigest
|
||||||
raise ActiveStorage::IntegrityError
|
raise ActiveStorage::IntegrityError
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,24 @@ if SERVICE_CONFIGURATIONS[:s3]
|
||||||
service.delete key
|
service.delete key
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
else
|
else
|
||||||
puts "Skipping S3 Service tests because no S3 configuration was supplied"
|
puts "Skipping S3 Service tests because no S3 configuration was supplied"
|
||||||
|
|
Loading…
Reference in a new issue