aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_storage
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2017-07-08 15:13:02 -0700
committerJeremy Daer <jeremydaer@gmail.com>2017-07-08 15:15:21 -0700
commit03120ecb50016fc210945d0824c11d9308b28372 (patch)
treeefe28698e7886dde03681b03dfdc1db9c7d07475 /lib/active_storage
parent255b1a149c8be93ede25404c53933bde3acc2dc2 (diff)
downloadrails-03120ecb50016fc210945d0824c11d9308b28372.tar.gz
rails-03120ecb50016fc210945d0824c11d9308b28372.tar.bz2
rails-03120ecb50016fc210945d0824c11d9308b28372.zip
Disk storage: ensure URLs end with the blob filename since some user agents don't respect Content-Disposition filename
Diffstat (limited to 'lib/active_storage')
-rw-r--r--lib/active_storage/disk_controller.rb4
-rw-r--r--lib/active_storage/engine.rb2
-rw-r--r--lib/active_storage/service/disk_service.rb4
3 files changed, 5 insertions, 5 deletions
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