【发布时间】:2020-05-15 20:39:49
【问题描述】:
我有一个将图像上传到 node.js 服务器的 from,我想处理传入的图像数据并将其转换为 base64。
我可以使用以下方法在服务器上写出文件:
fs.writeFile('filename.ext', req.files[0].buffer, { encoding: 'ucs2' }, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
但想做类似的事情
let b64 = fs.readFileSync(req.files[0].buffer, 'ucs2');
console.log(b64); // Outputs string of base-64 text.
我目前在使用此方法时遇到错误:
[ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes
这可以通过 node.js 实现吗?
我应该考虑哪些方法?
【问题讨论】:
标签: node.js encoding base64 decode ucs2