Javascript 如何在NodeEmailer中以电子邮件附件的形式从axios AJAX请求发送PDF blob
下面的代码将一些html发送到node.js API并将其转换为PDF。然后我想把PDF作为附件发送。文档说,处理流/文件路径等是通过附件的Javascript 如何在NodeEmailer中以电子邮件附件的形式从axios AJAX请求发送PDF blob,javascript,node.js,stream,axios,nodemailer,Javascript,Node.js,Stream,Axios,Nodemailer,下面的代码将一些html发送到node.js API并将其转换为PDF。然后我想把PDF作为附件发送。文档说,处理流/文件路径等是通过附件的内容属性完成的,但我不确定如何处理我的blob数据 我尝试了以下操作,但它导致节点错误无效的非字符串/缓冲区块。我可以在content中发送随机文本的电子邮件,它附带了一个PDF,但不可读 如何在不保存文件的情况下获取blob数据并将其作为PDF附件发送 emailInvoice () { Axios({ method: 'post',
内容属性完成的,但我不确定如何处理我的blob数据
我尝试了以下操作,但它导致节点错误无效的非字符串/缓冲区块
。我可以在content
中发送随机文本的电子邮件,它附带了一个PDF,但不可读
如何在不保存文件的情况下获取blob数据并将其作为PDF附件发送
emailInvoice () {
Axios({
method: 'post',
url: 'http://myApi/api/html-to-pdf',
data: {
html: this.getInvoiceHtml()
},
responseType: 'blob'
}).then(function (pdfResponse) {
Axios.post('http://localhost:4000/api/send-email', {
host: '##',
port: '26',
user: '##',
pass: '##',
to: '##',
from: '##',
subject: 'Invoice ' + this.model.doc.ref,
text: 'Test Text',
html: '<b>TEST</b>',
attachments: [{
filename: this.model.doc.ref + '.pdf',
content: pdfResponse.data,
contentType: 'application/pdf'
}]
}).then(function (response) {
console.log('Email Success')
console.log(response)
}).catch(function (error) {
console.log('Email Error')
console.log(error)
})
}.bind(this)).catch(function (error) {
console.log('PDF Error')
console.log(error)
})
}
emailInvoice(){
Axios({
方法:“post”,
网址:'http://myApi/api/html-to-pdf',
数据:{
html:this.getInvoiceHtml()
},
响应类型:“blob”
}).then(函数(pdfResponse){
轴心柱http://localhost:4000/api/send-电邮‘’{
主持人:"##",,
港口:'26',
用户:‘##’,
通过:“##”,
致:“##”,
发件人:“##”,
主题:“发票”+this.model.doc.ref,
文本:“测试文本”,
html:'测试',
附件:[{
文件名:this.model.doc.ref+'.pdf',
内容:pdfResponse.data,
contentType:'应用程序/pdf'
}]
}).然后(功能(响应){
console.log('Email Success')
console.log(响应)
}).catch(函数(错误){
console.log('电子邮件错误')
console.log(错误)
})
}.bind(this)).catch(函数(错误){
console.log('PDF错误')
console.log(错误)
})
}
编辑-我已尝试删除响应类型:“blob”
,因此我的数据看起来像:
%PDF-1.4↵10 obj↵↵endobj↵20 obj↵