mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix issue ActiveStorage direct upload disk
Fix an issue in ActiveStorage where a direct upload to disk storage would fail due to a content type mismatch if the file was uploaded using a mime-type synonym.
This commit is contained in:
parent
4429540995
commit
1986048d27
2 changed files with 12 additions and 1 deletions
|
@ -61,6 +61,7 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
|
|||
end
|
||||
|
||||
def acceptable_content?(token)
|
||||
token[:content_type] == request.content_type && token[:content_length] == request.content_length
|
||||
Mime::Type.lookup(request.content_type) == token[:content_type] &&
|
||||
token[:content_length] == request.content_length
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,6 +67,16 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_not blob.service.exist?(blob.key)
|
||||
end
|
||||
|
||||
test "directly uploading blob with different but equivalent content type" do
|
||||
data = "Something else entirely!"
|
||||
blob = create_blob_before_direct_upload(
|
||||
byte_size: data.size, checksum: Digest::MD5.base64digest(data), content_type: "application/x-gzip")
|
||||
|
||||
put blob.service_url_for_direct_upload, params: data, headers: { "Content-Type" => "application/x-gzip" }
|
||||
assert_response :no_content
|
||||
assert_equal data, blob.download
|
||||
end
|
||||
|
||||
test "directly uploading blob with mismatched content length" do
|
||||
data = "Something else entirely!"
|
||||
blob = create_blob_before_direct_upload byte_size: data.size - 1, checksum: Digest::MD5.base64digest(data)
|
||||
|
|
Loading…
Reference in a new issue