you cannot convert Base64 to UTF-8. Leave this as normal ASCII:
file = Tempfile.new('labelimg', :encoding => 'ascii-8bit')
file.write Base64.decode64(@image)
file.close
or even better - leave it as binary:
file = Tempfile.new('labelimg')
file.write Base64.decode64(@image)
file.close
UTF-8 is a multibyte format and cannot be used to transmit binary data such as photographs.
source
share