javascript - Load pdf from remote url to send as Mandrill attachment -
i trying load pdf in cloud code , send attachment mandrill.
as mandrill needs base64 encoded string attachment use buffer change encoding.
the result right pdf attachment cannot opened , think error caused recoding.
i guessed text returned request utf8 i'm not sure.
any suggestions?
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 buffer var buf = new buffer('httpresponse.text', 'utf8'); // encode text base64 promise.resolve(buf.tostring('base64')); }, error: function (httpresponse) { console.error(httpresponse); console.error("token request failed response code " + httpresponse.status); } }); return promise; }
the result of function put
"attachments": [ { "type": "application/pdf", "name": "test.pdf", "content": encodepdftext }
i had same problem recently, try following code, make sure httpresponse.text in utf8...
"content": new buffer(httpresponse.text.tostring('base64')).tostring()
Comments
Post a Comment