I have a problem to Store file (from a remote API) in MongoDB, i’m with Ruby 1.9
class Foo
include ::MongoMapper::Document
key :bar, String
end
I get the following error : “\xFF” from ASCII-8BIT to UTF-8
I tried the following things :
foo.bar = pdf_data.encode('UTF-8')
foo.bar = pdf_data.force_encoding('UTF-8')
foo.bar = pdf_data.ensure_encoding('UTF-8',
:external_encoding => :sniff,
:invalid_characters => :transcode
) # with github.com/Manfred/Ensure-encoding
Well any of them work, I get an error while save call …
I look on the net but I didn’t find any clear responce (or at least solving my probleme)…
Any idea what i’m supposed to do to be able to store it ?
If you are using
TempFile, make sure you put it into binary mode. An example: