instance method open

Ruby on Rails edge

Since v6.0.6.1

Available in: v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

Signature

open(tmpdir: nil, &block)

Downloads the blob to a temporary file on disk. If a block is given, the file is automatically closed and unlinked after the block executed. Otherwise the file is returned and you are responsible for closing and unlinking.

The tempfile’s name is prefixed with ActiveStorage- and the blob’s ID. Its extension matches that of the blob.

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

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 349
  def open(tmpdir: nil, &block)
    if local_io
      open_local_io(tmpdir: tmpdir, &block)
    else
      service.open(
        key,
        checksum: checksum,
        verify: !composed,
        name: [ "ActiveStorage-#{id}-", filename.extension_with_delimiter ],
        tmpdir: tmpdir,
        &block
      )
    end
  end

Defined in activestorage/app/models/active_storage/blob.rb line 349 · 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