diff --git a/activestorage/app/controllers/active_storage/blobs/proxy_controller.rb b/activestorage/app/controllers/active_storage/blobs/proxy_controller.rb index cc90c6b94b..7e43b60403 100644 --- a/activestorage/app/controllers/active_storage/blobs/proxy_controller.rb +++ b/activestorage/app/controllers/active_storage/blobs/proxy_controller.rb @@ -17,7 +17,7 @@ class ActiveStorage::Blobs::ProxyController < ActiveStorage::BaseController 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 diff --git a/activestorage/app/controllers/active_storage/representations/proxy_controller.rb b/activestorage/app/controllers/active_storage/representations/proxy_controller.rb index c31c7bd4a4..7e98c2184f 100644 --- a/activestorage/app/controllers/active_storage/representations/proxy_controller.rb +++ b/activestorage/app/controllers/active_storage/representations/proxy_controller.rb @@ -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 diff --git a/activestorage/test/controllers/blobs/proxy_controller_test.rb b/activestorage/test/controllers/blobs/proxy_controller_test.rb index 83bcf3f0f8..443539aded 100644 --- a/activestorage/test/controllers/blobs/proxy_controller_test.rb +++ b/activestorage/test/controllers/blobs/proxy_controller_test.rb @@ -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 diff --git a/activestorage/test/controllers/representations/proxy_controller_test.rb b/activestorage/test/controllers/representations/proxy_controller_test.rb index 8ae815ea1d..67665e99db 100644 --- a/activestorage/test/controllers/representations/proxy_controller_test.rb +++ b/activestorage/test/controllers/representations/proxy_controller_test.rb @@ -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,