instance method open

Ruby on Rails 8.1.4.1

Since v6.0.6.1

Available in: v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.4 v8.0.5.2 v8.1.4.1 edge

Signature

open(tmpdir: nil, &block)

Downloads the blob to a tempfile on disk. Yields the tempfile.

The tempfile’s name is prefixed with ActiveStorage- and the blob’s ID. It keeps the blob filename’s extension when that extension denotes the blob’s content type, and has no extension otherwise.

By default, the tempfile is created in Dir.tmpdir. Pass tmpdir: to create it in a different directory:

blob.open(tmpdir: "/path/to/tmp") do |file|
  # ...
end

The tempfile is automatically closed and unlinked after the given block is executed.

Raises ActiveStorage::IntegrityError if the downloaded data does not match the blob’s checksum.

Parameters

tmpdir key = nil
block block
Source
# File activestorage/app/models/active_storage/blob.rb, line 320
  def open(tmpdir: nil, &block)
    service.open(
      key,
      checksum: checksum,
      verify: !composed,
      name: [ "ActiveStorage-#{id}-", tempfile_extension ],
      tmpdir: tmpdir,
      &block
    )
  end

Defined in activestorage/app/models/active_storage/blob.rb line 320 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveStorage::Blob

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close