【发布时间】:2014-11-16 09:54:25
【问题描述】:
我正在尝试在 Cloud Code 中加载 Pdf 并将其作为附件与 mandrill 一起发送。
由于 mandrill 需要一个 base64 编码的字符串作为附件,我使用 Buffer 来更改编码。
现在的结果是一个无法打开的 Pdf 附件,我认为错误是由我的重新编码引起的。
我猜 get 请求返回的文本是 utf8 但我不确定。
有什么建议吗?
var Buffer = require('buffer').Buffer;
function loadPdf(pdfUrl) {
var promise = new Parse.Promise();
Parse.Cloud.httpRequest({
method: 'GET',
url: pdfUrl,
success: function (httpResponse) {
// Put text into buffer
var buf = new Buffer('httpResponse.text', 'utf8');
// encode text with base64
promise.resolve(buf.toString('base64'));
},
error: function (httpResponse) {
console.error(httpResponse);
console.error("Token Request failed with response code " + httpResponse.status);
}
});
return promise;
}
这个函数的结果放入
"attachments": [
{
"type": "application/pdf",
"name": "test.pdf",
"content": encodePdfText
}
【问题讨论】:
标签: javascript pdf parse-platform mandrill