aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-05-02 18:56:09 -0400
committerGeorge Claghorn <george@basecamp.com>2018-05-02 18:56:09 -0400
commit847342c25c61acaea988430dc3ab66a82e3ed486 (patch)
tree54ceaaeb4e1d22dfc1efcaddb5ee6acee773bd86 /activestorage
parentfc888952142d9aec5827a30ac8e333fdc27f4a22 (diff)
downloadrails-847342c25c61acaea988430dc3ab66a82e3ed486.tar.gz
rails-847342c25c61acaea988430dc3ab66a82e3ed486.tar.bz2
rails-847342c25c61acaea988430dc3ab66a82e3ed486.zip
Stream blobs from disk
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/app/controllers/active_storage/disk_controller.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activestorage/app/controllers/active_storage/disk_controller.rb b/activestorage/app/controllers/active_storage/disk_controller.rb
index 7bc5eb3fdb..63918eb6f4 100644
--- a/activestorage/app/controllers/active_storage/disk_controller.rb
+++ b/activestorage/app/controllers/active_storage/disk_controller.rb
@@ -5,21 +5,30 @@
# Always go through the BlobsController, or your own authenticated controller, rather than directly
# to the service url.
class ActiveStorage::DiskController < ActiveStorage::BaseController
+ include ActionController::Live
+
skip_forgery_protection
def show
if key = decode_verified_key
- send_data disk_service.download(key),
- disposition: params[:disposition], content_type: params[:content_type]
+ response.headers["Content-Type"] = params[:content_type] || DEFAULT_SEND_FILE_TYPE
+ response.headers["Content-Disposition"] = params[:disposition] || DEFAULT_SEND_FILE_DISPOSITION
+
+ disk_service.download key do |chunk|
+ response.stream.write chunk
+ end
else
head :not_found
end
+ ensure
+ response.stream.close
end
def update
if token = decode_verified_token
if acceptable_content?(token)
disk_service.upload token[:key], request.body, checksum: token[:checksum]
+ head :no_content
else
head :unprocessable_entity
end
@@ -28,6 +37,8 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
end
rescue ActiveStorage::IntegrityError
head :unprocessable_entity
+ ensure
+ response.stream.close
end
private