module FileBlobs::ActionControllerDataStreamingExtensions
Module mixed into ActionController::DataStreaming.
Constants
- ETAG
- HTTP_IF_NONE_MATCH
Protected Instance Methods
send_file_blob(proxy, options = {})
click to toggle source
Sends a file blob to the browser.
This method uses HTTP’s strong etag feature to facilitate serving the files from a cache whenever possible.
@param [FileBlobs::FileBlobProxy] proxy a proxy for a collection of
attributes generated by has_file_blob
@param [Hash<Symbol, Object>] options tweaks the options passed to the
underlying send_data call; this method sets the :filename and :type options, but their values can be overridden by the options hash
@see ActionController::DataStreaming#send_data
# File lib/file_blobs_rails/action_controller_data_streaming_extensions.rb, line 21 def send_file_blob(proxy, options = {}) if request.get_header(HTTP_IF_NONE_MATCH) == proxy.blob_id head :not_modified else response.headers[ETAG] = proxy.blob_id send_options = { type: proxy.mime_type, filename: proxy.original_name } send_options.merge! options send_data proxy.data, send_options end end