diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-01-15 13:06:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-15 13:06:17 -0500 |
commit | c2ba530c43244b5b60fd629f61cd8b44c43ecda9 (patch) | |
tree | 76c572f419a8e30b4ba2d2ae22570844ba28361e /activestorage/lib/active_storage/service | |
parent | d8e7d6b03c50f4f01c333461c46666d8210e2c17 (diff) | |
download | rails-c2ba530c43244b5b60fd629f61cd8b44c43ecda9.tar.gz rails-c2ba530c43244b5b60fd629f61cd8b44c43ecda9.tar.bz2 rails-c2ba530c43244b5b60fd629f61cd8b44c43ecda9.zip |
Extract content types from blob data
Diffstat (limited to 'activestorage/lib/active_storage/service')
-rw-r--r-- | activestorage/lib/active_storage/service/disk_service.rb | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/activestorage/lib/active_storage/service/disk_service.rb b/activestorage/lib/active_storage/service/disk_service.rb index a8728c5bc3..27769db584 100644 --- a/activestorage/lib/active_storage/service/disk_service.rb +++ b/activestorage/lib/active_storage/service/disk_service.rb @@ -9,10 +9,10 @@ module ActiveStorage # Wraps a local disk path as an Active Storage service. See ActiveStorage::Service for the generic API # documentation that applies to all services. class Service::DiskService < Service - attr_reader :root + attr_reader :root, :host - def initialize(root:) - @root = root + def initialize(root:, host:) + @root, @host = root, host end def upload(key, io, checksum: nil) @@ -69,14 +69,13 @@ module ActiveStorage verified_key_with_expiration = ActiveStorage.verifier.generate(key, expires_in: expires_in, purpose: :blob_key) generated_url = - if defined?(Rails.application) - Rails.application.routes.url_helpers.rails_disk_service_path \ - verified_key_with_expiration, - filename: filename, disposition: content_disposition_with(type: disposition, filename: filename), content_type: content_type - else - "/rails/active_storage/disk/#{verified_key_with_expiration}/#{filename}?content_type=#{content_type}" \ - "&disposition=#{content_disposition_with(type: disposition, filename: filename)}" - end + Rails.application.routes.url_helpers.rails_disk_service_url( + verified_key_with_expiration, + filename: filename, + disposition: content_disposition_with(type: disposition, filename: filename), + content_type: content_type, + host: host + ) payload[:url] = generated_url @@ -97,12 +96,7 @@ module ActiveStorage purpose: :blob_token } ) - generated_url = - if defined?(Rails.application) - Rails.application.routes.url_helpers.update_rails_disk_service_path verified_token_with_expiration - else - "/rails/active_storage/disk/#{verified_token_with_expiration}" - end + generated_url = Rails.application.routes.url_helpers.update_rails_disk_service_url(verified_token_with_expiration, host: host) payload[:url] = generated_url |