AnA*_*ice 6 postgresql encoding ruby-on-rails heroku ruby-on-rails-3
我从Cloudmailin收集Rails电子邮件时收到以下PGError:
PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xbb HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". : INSERT INTO "comments" ("content") VALUES ('Reply with blah blah ????????????????????????????????????????????????????? .....
Run Code Online (Sandbox Code Playgroud)
所以很明显我有一些无效的UTF8字符进入电子邮件吧?所以我试着清理它,但仍有一些东西在偷偷摸摸.这是我到目前为止所拥有的:
message_all_clean = params[:message]
Iconv.conv('UTF-8//IGNORE', 'UTF-8', message_all_clean)
message_plain_clean = params[:plain]
Iconv.conv('UTF-8//IGNORE', 'UTF-8', message_plain_clean)
@incoming_mail = IncomingMail.create(:message_all => Base64.encode64(message_all_clean), :message_plain => Base64.encode64(message_plain_clean))
Run Code Online (Sandbox Code Playgroud)
任何想法,想法或建议?谢谢
当在Heroku上遇到此问题时,我们转换为US-ASCII以适当地清理传入的数据(即从Word粘贴):
Iconv.conv("UTF-8//IGNORE", "US-ASCII", content)
Run Code Online (Sandbox Code Playgroud)
有了这个,我们没有更多的字符编码问题.
另外,请仔细检查是否存在其他需要相同转换的字段,因为它可能会影响将文本块传递到数据库的任何内容.
| 归档时间: |
|
| 查看次数: |
3896 次 |
| 最近记录: |