diff options
author | Janko Marohnić <janko.marohnic@gmail.com> | 2018-04-22 23:43:11 +0200 |
---|---|---|
committer | Janko Marohnić <janko.marohnic@gmail.com> | 2018-04-22 23:43:11 +0200 |
commit | 0d811fd4826e9a8b3d493a32d1315b681263ad3f (patch) | |
tree | 16c7745fc0723210adcf1336472ae687472e0ea2 | |
parent | f01e2498905ec057e6c8872d15f8dea18d4cbde8 (diff) | |
download | rails-0d811fd4826e9a8b3d493a32d1315b681263ad3f.tar.gz rails-0d811fd4826e9a8b3d493a32d1315b681263ad3f.tar.bz2 rails-0d811fd4826e9a8b3d493a32d1315b681263ad3f.zip |
Ensure result file is deleted on uploading errors
-rw-r--r-- | activestorage/app/models/active_storage/variant.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/activestorage/app/models/active_storage/variant.rb b/activestorage/app/models/active_storage/variant.rb index 450ce3677f..8ee9e75d6b 100644 --- a/activestorage/app/models/active_storage/variant.rb +++ b/activestorage/app/models/active_storage/variant.rb @@ -100,9 +100,9 @@ class ActiveStorage::Variant def process download_blob_to_tempfile do |image| - variant = transform image - upload variant - variant.close! + transform image do |output| + upload output + end end end @@ -121,7 +121,13 @@ class ActiveStorage::Variant def transform(image) format = "png" unless WEB_IMAGE_CONTENT_TYPES.include?(blob.content_type) - variation.transform(image, format: format) + result = variation.transform(image, format: format) + + begin + yield result + ensure + result.close! + end end def upload(file) |