【发布时间】:2020-10-15 07:58:05
【问题描述】:
我已使用 rails 中的 binary 数据类型将 base64url_encoded 字符串存储到 postgres 数据库中。这是迁移
def change
add_column :gmail_attachments, :base64_data, :binary
end
我存储的数据是来自gmail API 的base64 url 编码字符串。当我尝试在 postgres 中将数据存储为 string 数据类型时,我得到了
ArgumentError(字符串包含空字节)
所以,我选择了二进制数据类型,并将其成功存储到数据库中。现在,当我尝试时
render status: 200, json: gmail_attachment_record
我收到以下错误
Encoding::UndefinedConversionError ("\xFF" 从 ASCII-8BIT 到 UTF-8):
如何消除此错误并返回存储的数据?我是否将其存储在错误的数据类型中?要实现这一点,rails ActiveRecord 数据类型的最佳选择是什么?
【问题讨论】:
-
nishantnigam.in/2012/01/… - 检查这篇文章是否对你有帮助
标签: ruby-on-rails postgresql activerecord gmail-api