Skip to content

Commit

Permalink
Ensure result file is deleted on uploading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Apr 22, 2018
1 parent f01e249 commit 0d811fd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions activestorage/app/models/active_storage/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def processed?

def process
download_blob_to_tempfile do |image|
variant = transform image
upload variant
variant.close!
transform image do |output|
upload output
end
end
end

Expand All @@ -121,7 +121,13 @@ def content_type

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)
Expand Down

0 comments on commit 0d811fd

Please sign in to comment.