Spec-Zone.ru › Ruby on Rails 8.1

module ActiveStorage::Streaming

Подключённые модули:
ActionController::DataStreaming, ActionController::Live

Константы

DEFAULT_BLOB_STREAMING_DISPOSITION

Закрытые методы экземпляра

send_blob_stream (blob, disposition: nil) Показать исходный код
# File activestorage/app/controllers/concerns/active_storage/streaming.rb, line 56
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
    expires_now
    head :not_found
  rescue
    # Status and caching headers are already set, but not committed.
    # Change the status to 500 manually.
    expires_now
    head :internal_server_error
    raise
  end
end

Передаёт блоб из хранилища непосредственно в ответ. Способ обработки можно задать с помощью disposition. Тип содержимого и имя файла задаются непосредственно из blob.

© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API