instance method send_data

Ruby on Rails 7.0.10

Since v3.1.12 Private

Available in: v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

send_data(data, options = {})

Sends the given binary data to the browser. This method is similar to render plain: data, but also allows you to specify whether the browser should display the response as a file attachment (i.e. in a download dialog) or as inline data. You may also set the content type, the file name, and other things.

Options:

  • :filename - suggests a filename for the browser to use.

  • :type - specifies an HTTP content type. Defaults to application/octet-stream. You can specify either a string or a symbol for a registered type with Mime::Type.register, for example :json. If omitted, type will be inferred from the file extension specified in :filename. If no content type is registered for the extension, the default type application/octet-stream will be used.

  • :disposition - specifies whether the file will be shown inline or downloaded. Valid values are "inline" and "attachment" (default).

  • :status - specifies the status code to send with the response. Defaults to 200.

Generic data download:

send_data buffer

Download a dynamically-generated tarball:

send_data generate_tgz('dir'), filename: 'dir.tgz'

Display an image Active Record in the browser:

send_data image.data, type: image.content_type, disposition: 'inline'

See send_file for more information on HTTP Content-* headers and caching.

Parameters

data req
options opt = {}
Source
# File actionpack/lib/action_controller/metal/data_streaming.rb, line 109
      def send_data(data, options = {}) # :doc:
        send_file_headers! options
        render options.slice(:status, :content_type).merge(body: data)
      end

Defined in actionpack/lib/action_controller/metal/data_streaming.rb line 109 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::DataStreaming

Type at least 2 characters to search.

↑↓ navigate · open · esc close