diff --git a/lib/templates/create_attachments.rb b/lib/templates/create_attachments.rb index ee2b9a8d5..197e8b52b 100644 --- a/lib/templates/create_attachments.rb +++ b/lib/templates/create_attachments.rb @@ -100,13 +100,15 @@ module Templates Zip::File.open(file.tempfile).each do |entry| next if entry.directory? - total_size += entry.size + tempfile = Tempfile.new(entry.name) + tempfile.binmode + + total_size += entry.get_input_stream do |in_stream| + IO.copy_stream(in_stream, tempfile, MAX_ZIP_SIZE - total_size + 1) + end raise InvalidFileType, 'zip_too_large' if total_size > MAX_ZIP_SIZE - tempfile = Tempfile.new(entry.name) - tempfile.binmode - entry.get_input_stream { |in_stream| IO.copy_stream(in_stream, tempfile) } tempfile.rewind type = Marcel::MimeType.for(tempfile, name: entry.name)