instance method
open
Ruby on Rails 8.1.2
Since v6.0.6Signature
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. 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
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
-
tmpdirkey = nil -
blockblock
Source
# File activestorage/app/models/active_storage/blob.rb, line 288
def open(tmpdir: nil, &block)
service.open(
key,
checksum: checksum,
verify: !composed,
name: [ "ActiveStorage-#{id}-", filename.extension_with_delimiter ],
tmpdir: tmpdir,
&block
)
end
Defined in activestorage/app/models/active_storage/blob.rb line 288
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveStorage::Blob