MongoMapper 错误“\xFF”在数据库中存储文件时从 ASCII-8BIT 到 UTF-8
我在 MongoDB 中存储文件(来自远程 API)时遇到问题,我使用的是 Ruby 1.9
class Foo
include ::MongoMapper::Document
key :bar, String
end
我收到以下错误:“\xFF”从 ASCII-8BIT 到 UTF-8
我尝试了以下操作:
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
好吧,其中任何一个工作时,我在保存调用时遇到错误...
我在网上查找,但没有找到任何明确的响应(或至少解决我的问题)... 知道我应该做什么才能存储它吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 TempFile,请确保将其设置为二进制模式。一个例子:
If you are using
TempFile
, make sure you put it into binary mode. An example: