[英]How to fetch remote PDF from a url and send to the client with Express js?
[英]Load pdf from remote url to send as Mandrill attachment
我正在嘗試在Cloud Code中加載Pdf並將其作為附件與mandrill發送。
由於山d需要附件的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
}
我最近遇到了相同的問題,請嘗試以下代碼,確保httpResponse.text位於utf8中...
"content": new Buffer(httpResponse.text.toString('base64')).toString()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.