Skip to content

Commit

Permalink
Change the path for temporary files to use the OS default. (#32)
Browse files Browse the repository at this point in the history
Previously, all temporary files would be briefly created within the same directory as the original PDF file and destroyed shortly after. This did not work on read-only file systems, such as the ones provided by AWS lambda. Now all temporary files are stored in a directory that is defined by the operating system, which is writeable in AWS Lambda.
  • Loading branch information
vkononov authored Dec 5, 2022
1 parent e49c73d commit 6192add
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/fillable-pdf.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative 'fillable-pdf/itext'
require_relative 'field'
require 'base64'
require 'fileutils'
require 'securerandom'
require 'tmpdir'

class FillablePDF # rubocop:disable Metrics/ClassLength
##
Expand Down Expand Up @@ -148,7 +148,7 @@ def set_image(key, file_path) # rubocop:disable Metrics/AbcSize, Metrics/MethodL
# @param [String|Symbol] base64_image_data base64 encoded data image
#
def set_image_base64(key, base64_image_data)
tmp_file = SecureRandom.uuid
tmp_file = "#{Dir.tmpdir}/#{SecureRandom.uuid}"
File.binwrite(tmp_file, Base64.decode64(base64_image_data))
set_image(key, tmp_file)
ensure
Expand Down Expand Up @@ -214,7 +214,7 @@ def values
# @param [bool] flatten true if PDF should be flattened, false otherwise
#
def save(flatten: false)
tmp_file = SecureRandom.uuid
tmp_file = "#{Dir.tmpdir}/#{SecureRandom.uuid}"
save_as(tmp_file, flatten: flatten)
FileUtils.mv tmp_file, @file_path
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fillable-pdf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class FillablePDF
VERSION = '0.9.5.1'
VERSION = '0.9.5.2'
end

0 comments on commit 6192add

Please sign in to comment.