lib/isodoc/function/utils.rb in isodoc-1.0.7 vs lib/isodoc/function/utils.rb in isodoc-1.0.8

- old
+ new

@@ -150,14 +150,21 @@ gsub('&lt;', '&#x3c;').gsub('&gt;', '&#x3e;').gsub('&amp;', '&#x26;') end def save_dataimage(uri, relative_dir = true) %r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri - uuid = UUIDTools::UUID.random_create.to_s - fname = "#{uuid}.#{imgtype}" - new_file = File.join(tmpimagedir, fname) - @files_to_delete << new_file - File.open(new_file, "wb") { |f| f.write(Base64.strict_decode64(imgdata)) } - File.join(relative_dir ? rel_tmpimagedir : tmpimagedir, fname) + #uuid = UUIDTools::UUID.random_create.to_s + #fname = "#{uuid}.#{imgtype}" + #new_file = File.join(tmpimagedir, fname) + #@files_to_delete << new_file + #File.open(new_file, "wb") { |f| f.write(Base64.strict_decode64(imgdata)) } + #File.join(relative_dir ? rel_tmpimagedir : tmpimagedir, fname) + imgtype = "png" unless /^[a-z0-9]+$/.match imgtype + Tempfile.open(["image", ".#{imgtype}"]) do |f| + f.binmode + f.write(Base64.strict_decode64(imgdata)) + @tempfile_cache << f #persist to the end + f.path + end end end end