node.js sendgrid如何附加pdf [英] node.js sendgrid how to attach a pdf

查看:104
本文介绍了node.js sendgrid如何附加pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sendgrid 在我的node.js应用程序中发送电子邮件.我尝试附加pdf的每种组合最终都会导致我附加的pdf无法阅读.

Im using sendgrid to send email in my node.js application. Every combination I try to attach a pdf ends up with my attached pdf being unreadable.

我尝试过:

fs.readFile('public_html/img/Report.pdf',function(err,data){
        var base64data = new Buffer(data).toString('base64');

        sendgrid.send({
            to        : hexDecode(_.e),
            from      : 'xxxxxxxxx@gmail.com',
            subject   : 'Report',

            files     : [{filename:'Report.pdf',content:'data:application/pdf;base64,'+base64data}],
            //files   : [{filename:'Report.pdf',contentType:'data:application/pdf',url:'public_html/img/'Report.pdf'}],
            //files   : [{filename:'Report.pdf',url:'public_html/img/'Report.pdf'}],
            html      : 'bla bla'

有人知道如何防止无法加载pdf文档"吗?

does any one know how to prevent 'Failed to load pdf document'??

推荐答案

根据自述文件 ,您应该只传递您的内容,而不要将其转换为数据URI.

According to the README, you should just pass your content, not turn it into a data URI.

fs.readFile('public_html/img/Report.pdf', function(err, data) {
    sendgrid.send({
        to        : hexDecode(_.e),
        from      : 'xxxxxxxxx@gmail.com',
        subject   : 'Report',

        files     : [{filename: 'Report.pdf', content: data}],
        html      : 'bla bla'

这篇关于node.js sendgrid如何附加pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆