Merge pull request #43637 from alxjrvs/blob-representation-disposition
Fix Rails 7 Regression - ActiveStorage Content Disposition
This commit is contained in:
commit
47fc79ca2b
@ -17,7 +17,7 @@ def show
|
||||
response.headers["Accept-Ranges"] = "bytes"
|
||||
response.headers["Content-Length"] = @blob.byte_size.to_s
|
||||
|
||||
send_blob_stream @blob
|
||||
send_blob_stream @blob, disposition: params[:disposition]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -9,7 +9,7 @@
|
||||
class ActiveStorage::Representations::ProxyController < ActiveStorage::Representations::BaseController
|
||||
def show
|
||||
http_cache_forever public: true do
|
||||
send_blob_stream @representation.image
|
||||
send_blob_stream @representation.image, disposition: params[:disposition]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -21,11 +21,17 @@ class ActiveStorage::Blobs::ProxyControllerTest < ActionDispatch::IntegrationTes
|
||||
assert_equal "application/octet-stream", response.headers["Content-Type"]
|
||||
end
|
||||
|
||||
test "forcing Content-Disposition to attachment" do
|
||||
test "forcing Content-Disposition to attachment based on type" do
|
||||
get rails_storage_proxy_url(create_blob(content_type: "application/zip"))
|
||||
assert_match(/^attachment; /, response.headers["Content-Disposition"])
|
||||
end
|
||||
|
||||
test "caller can change disposition to attachment" do
|
||||
url = rails_storage_proxy_url(create_blob(content_type: "image/jpeg"), disposition: :attachment)
|
||||
get url
|
||||
assert_match(/^attachment; /, response.headers["Content-Disposition"])
|
||||
end
|
||||
|
||||
test "signed ID within expiration date" do
|
||||
get rails_storage_proxy_url(create_file_blob(filename: "racecar.jpg"), expires_in: 1.minute)
|
||||
assert_response :success
|
||||
|
@ -8,6 +8,22 @@ class ActiveStorage::Representations::ProxyControllerWithVariantsTest < ActionDi
|
||||
@blob = create_file_blob filename: "racecar.jpg"
|
||||
end
|
||||
|
||||
test "showing variant attachment" do
|
||||
get rails_blob_representation_proxy_url(
|
||||
disposition: :attachment,
|
||||
filename: @blob.filename,
|
||||
signed_blob_id: @blob.signed_id,
|
||||
variation_key: ActiveStorage::Variation.encode(resize_to_limit: [100, 100]))
|
||||
|
||||
assert_response :ok
|
||||
assert_match(/^attachment/, response.headers["Content-Disposition"])
|
||||
|
||||
image = read_image(@blob.variant(resize_to_limit: [100, 100]))
|
||||
assert_equal 100, image.width
|
||||
assert_equal 67, image.height
|
||||
end
|
||||
|
||||
|
||||
test "showing variant inline" do
|
||||
get rails_blob_representation_proxy_url(
|
||||
filename: @blob.filename,
|
||||
|
Loading…
Reference in New Issue
Block a user