【问题标题】:Invalid UTF-8 detected in nodejs在 nodejs 中检测到无效的 UTF-8
【发布时间】:2017-10-02 04:05:22
【问题描述】:

我在使用 utf8quoted-printable 对电子邮件正文进行编码时遇到问题

bodyHtml = utf8.decode(quotedPrintable.decode(resData['body-html']));

在heroku日志中,它说

2017-05-04T05:49:54.312348+00:00 app[consumerWorker.1]: 
/app/node_modules/utf8/utf8.js:194
2017-05-04T05:49:54.312360+00:00 app[consumerWorker.1]:         throw 
Error('Invalid UTF-8 detected');
2017-05-04T05:49:54.312362+00:00 app[consumerWorker.1]:         ^
2017-05-04T05:49:54.312362+00:00 app[consumerWorker.1]: 
2017-05-04T05:49:54.312363+00:00 app[consumerWorker.1]: Error: Invalid 
UTF-8 detected

我创建了一个 runkit,https://runkit.com/kiranlm/590abc3746b5b70012ffd7f8

【问题讨论】:

    标签: javascript node.js heroku utf-8 quoted-printable


    【解决方案1】:

    如果您使用英文 utf-8,请尝试以下操作: 从终端运行

    heroku config:add LANG=en_US.UTF-8
    

    如果你想检查这个:

        $ heroku run bash
    Running bash attached to terminal... up, run.2
    u20415@022e95bf-3ab6-4291-97b1-741f95e7fbda:/app$ irb
    irb(main):001:0> "a".encoding
    => #<Encoding:UTF-8>
    

    【讨论】:

    • 谢谢@damian-lattenero,我试过了,现在heroku中的编码是utf8,但错误仍然存​​在,
    猜你喜欢
    • 2012-10-21
    • 2012-07-27
    • 2021-01-24
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 2021-01-27
    相关资源
    最近更新 更多