1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activestorage/app/controllers/concerns/active_storage/streaming.rb
David Heinemeier Hansson ab8e3d22cb
Extract ActiveStorage::Streaming so your own controllers can use it (#41440)
Extract ActiveStorage::Streaming so your own controller can use it
2021-02-19 15:40:56 +01:00

21 lines
734 B
Ruby

# frozen_string_literal: true
module ActiveStorage::Streaming
DEFAULT_BLOB_STREAMING_DISPOSITION = "inline"
include ActionController::Live
private
# Stream the blob from storage directly to the response. The disposition can be controlled by setting +disposition+.
# The content type and filename is set directly from the +blob+.
def send_blob_stream(blob, disposition: nil) #:doc:
send_stream(
filename: blob.filename.sanitized,
disposition: blob.forced_disposition_for_serving || disposition || DEFAULT_BLOB_STREAMING_DISPOSITION,
type: blob.content_type_for_serving) do |stream|
blob.download do |chunk|
stream.write chunk
end
end
end
end