Make sorting and attachments work

This commit is contained in:
2025-09-02 13:33:48 -05:00
parent 73f430eadf
commit ea56d33472
4 changed files with 33 additions and 5 deletions
@@ -107,7 +107,7 @@ module Suppliers
BASE64_IMAGE_MATCHER = /^data:image\/(\w+);base64,/ # data:image/png;base64,
# inspired by: https://stackoverflow.com/questions/32984963/upload-base64-encoded-image-with-paperclip-rails
def decode_base64_params(authorized_params, attributes = [])
tempfiles = []
@tempfiles = []
attributes = Array.wrap(attributes) # allow single attribute argument without array notation
attributes.each do |attribute|
if value = authorized_params[attribute].presence
@@ -115,6 +115,7 @@ module Suppliers
image_type = match[1]
decoded_attribute = Base64.decode64 value.sub BASE64_IMAGE_MATCHER, ''
file = Tempfile.new(['image', ".#{image_type}"])
tempfiles << file
file.binmode
file.write decoded_attribute
authorized_params[attribute] = file
@@ -126,7 +127,8 @@ module Suppliers
end
authorized_params
ensure
tempfiles.each &:unlink
@tempfiles.each &:rewind
# tempfiles.each &:unlink
end
end
end