Class: ActiveStorage::Blobs::ProxyController

Inherits:
ActiveStorage::BaseController
  • Object
show all
Includes:
SetBlob, Streaming
Defined in:
activestorage/app/controllers/active_storage/blobs/proxy_controller.rb

Overview

Proxy files through application. This avoids having a redirect and makes files easier to cache.

WARNING: All Active Storage controllers are publicly accessible by default. The generated URLs are hard to guess, but permanent by design. If your files require a higher level of protection consider implementing Authenticated Controllers.

Constant Summary

Constants included from Streaming

Streaming::DEFAULT_BLOB_STREAMING_DISPOSITION

Constants included from ActionController::DataStreaming

ActionController::DataStreaming::DEFAULT_SEND_FILE_DISPOSITION, ActionController::DataStreaming::DEFAULT_SEND_FILE_TYPE

Constants included from ActionController::Rendering

ActionController::Rendering::RENDER_FORMATS_IN_PRIORITY

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods included from ActionController::Live

#process, #response_body=, #send_stream

Methods included from ActionController::Rendering

#render, #render_to_body, #render_to_string

Instance Method Details

#showObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'activestorage/app/controllers/active_storage/blobs/proxy_controller.rb', line 13

def show
  if request.headers["Range"].present?
    send_blob_byte_range_data @blob, request.headers["Range"]
  else
    http_cache_forever public: true do
      response.headers["Accept-Ranges"] = "bytes"
      response.headers["Content-Length"] = @blob.byte_size.to_s

      send_blob_stream @blob, disposition: params[:disposition]
    end
  end
end