Skip to Content Skip to Search
Methods
S
Included Modules

Constants

DEFAULT_BLOB_STREAMING_DISPOSITION = "inline"
 

Instance Private methods

send_blob_stream(blob, disposition: nil)

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.

# File activestorage/app/controllers/concerns/active_storage/streaming.rb, line 63
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
  rescue ActiveStorage::FileNotFoundError
    raise if response.committed?

    expires_now
    head :not_found
  rescue
    # Until the first chunk is written, status and caching headers are set
    # but not committed. Change the status to 500 manually.
    unless response.committed?
      expires_now
      head :internal_server_error
    end

    raise
  end
end