From 03120ecb50016fc210945d0824c11d9308b28372 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Sat, 8 Jul 2017 15:13:02 -0700 Subject: Disk storage: ensure URLs end with the blob filename since some user agents don't respect Content-Disposition filename --- lib/active_storage/disk_controller.rb | 4 ++-- lib/active_storage/engine.rb | 2 +- lib/active_storage/service/disk_service.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/active_storage') diff --git a/lib/active_storage/disk_controller.rb b/lib/active_storage/disk_controller.rb index 9d5b52d66f..7149cc17a6 100644 --- a/lib/active_storage/disk_controller.rb +++ b/lib/active_storage/disk_controller.rb @@ -9,8 +9,8 @@ require "active_support/core_ext/object/inclusion" # if you are using the +Disk+ service. # # By default, mounting the Active Storage engine inside your application will -# define a +/rails/blobs/:encoded_key+ route that will reference this controller's -# +show+ action and will be used to serve local files. +# define a +/rails/blobs/:encoded_key/*filename+ route that will reference this +# controller's +show+ action and will be used to serve local files. # # A URL for an attachment can be generated through its +#url+ method, that # will use the aforementioned route. diff --git a/lib/active_storage/engine.rb b/lib/active_storage/engine.rb index 3512be0468..d35d3c16db 100644 --- a/lib/active_storage/engine.rb +++ b/lib/active_storage/engine.rb @@ -11,7 +11,7 @@ module ActiveStorage config.after_initialize do |app| app.routes.prepend do - get "/rails/blobs/:encoded_key" => "active_storage/disk#show", as: :rails_disk_blob + get "/rails/blobs/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_blob end end end diff --git a/lib/active_storage/service/disk_service.rb b/lib/active_storage/service/disk_service.rb index 6164caf86c..5576b3b125 100644 --- a/lib/active_storage/service/disk_service.rb +++ b/lib/active_storage/service/disk_service.rb @@ -43,9 +43,9 @@ class ActiveStorage::Service::DiskService < ActiveStorage::Service verified_key_with_expiration = ActiveStorage::VerifiedKeyWithExpiration.encode(key, expires_in: expires_in) if defined?(Rails) && defined?(Rails.application) - Rails.application.routes.url_helpers.rails_disk_blob_path(verified_key_with_expiration, disposition: disposition) + Rails.application.routes.url_helpers.rails_disk_blob_path(verified_key_with_expiration, disposition: disposition, filename: filename) else - "/rails/blobs/#{verified_key_with_expiration}?disposition=#{disposition}" + "/rails/blobs/#{verified_key_with_expiration}/#{filename}?disposition=#{disposition}" end end -- cgit v1.2.3