Skip to content

Commit

Permalink
Add binary mode to temporary files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashellmann committed Apr 1, 2024
1 parent eb772d1 commit 73995c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def create

if @encrypted
lockbox = Lockbox.new(key: current_user.secret_key)
temp_file = Tempfile.new('uploaded_file')
temp_file = Tempfile.new('uploaded_file', binmode: true)

begin
temp_file.write(@file.read)
temp_file.rewind
encrpyted_data = lockbox.encrypt(File.binread(temp_file.path))
File.open(Settings.document_folder + @file_name, 'w+b') {|f| f.write(encrypted_data)}
File.open(Settings.document_folder + @file_name, 'w+b') {|f| f.binwrite(encrypted_data)}
ensure
temp_file.close
temp_file.unlink
Expand Down Expand Up @@ -90,7 +90,7 @@ def download
if @document.encrypted_flag
lockbox = Lockbox.new(key: current_user.secret_key)
decrypted_data = lockbox.decrypt(File.binread(Settings.document_folder + @document.document_url))
temp_file = Tempfile.new('decrypted_file')
temp_file = Tempfile.new('decrypted_file', binmode: true)

begin
temp_file.write(decrypted_data)
Expand Down

0 comments on commit 73995c0

Please sign in to comment.