![](/img/trans.png)
[英]Encoding PDF to Base64 string and using Node.js Buffer.from() results in broken file
[英]TypeError Base64 is not a function when using Buffer.from in Node 4.3
我正在使用標准的亞馬遜機器映像(linux x64)在Node 4.3上本地調試lambda函數
當我運行程序時,我在函數中得到一個錯誤,該函數用於將base64字符串解碼為utf-8。 錯誤說
Unhandled rejection TypeError: base64 is not a function
at Function.from (native)
at Function.from (native)
at /home/ec2-user/sass-compiler/lib/compiler.module.js:26:30
我的代碼看起來很簡單。 我已經檢查了SO和節點4.3文檔 ,我的代碼似乎是合規的。 我有什么想法可能做錯了嗎?
template() {
return new Promise((resolve, reject) => {
let buf = Buffer.from(this._opts.tpl, 'base64').toString('utf-8');
let _tpl = _.template(buf);
resolve(_tpl(this._opts.opts));
});
}
編輯該程序使用Node LTS 6.9.5在Windows 10上運行正常
我終於在Stack Overflow上找到了回答這個問題的答案。
在節點5.3及以下,您需要使用緩沖區構造函數(即: new Buffer
)而不是Buffer.from
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.