From 847342c25c61acaea988430dc3ab66a82e3ed486 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Wed, 2 May 2018 18:56:09 -0400 Subject: Stream blobs from disk --- .../app/controllers/active_storage/disk_controller.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'activestorage/app') 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 -- cgit v1.2.3