aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/models
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-05-30 20:01:07 -0400
committerGeorge Claghorn <george@basecamp.com>2018-05-30 20:05:39 -0400
commita6d80e164f2f5566472370a84ab7cd98736666c4 (patch)
treebde6f7b857255fd12d81702d23debd7b995876c2 /activestorage/app/models
parente2e053608ed71d22d7f3e22af605ab284ef00f05 (diff)
downloadrails-a6d80e164f2f5566472370a84ab7cd98736666c4.tar.gz
rails-a6d80e164f2f5566472370a84ab7cd98736666c4.tar.bz2
rails-a6d80e164f2f5566472370a84ab7cd98736666c4.zip
Include blob ID in tempfile name for debugging convenience
Diffstat (limited to 'activestorage/app/models')
-rw-r--r--activestorage/app/models/active_storage/blob.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb
index d36c951292..203e4118c5 100644
--- a/activestorage/app/models/active_storage/blob.rb
+++ b/activestorage/app/models/active_storage/blob.rb
@@ -168,6 +168,16 @@ class ActiveStorage::Blob < ActiveRecord::Base
# 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 <tt>Dir.tmpdir</tt>. Pass +tempdir:+ to create it in a different directory:
+ #
+ # blob.open(tempdir: "/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.
def open(tempdir: nil, &block)
ActiveStorage::Downloader.new(self, tempdir: tempdir).download_blob_to_tempfile(&block)