我将文件作为base64字符串发送到node.js服务器,然后我需要将其作为二进制文件发送到外部服务。是否可以在不将文件保存到文件系统的情况下执行此操作?现在我正在尝试以这种方式在node.js端获取文件:
var fileData = req.body.value,
fileName = req.body.id,
base64Data = fileData.replace(/^data:image\/jpeg;base64,/,"");
modules.fs.writeFile(
fileName,
base64Data,
'base64',
function(err)
{
if (err)
{
console.log(err);
}
else
{
//read file from the file system and send to the external service
}
});
答案 0 :(得分:0)
将其写入缓冲区:
var buffer = new Buffer(base64Data, 'base64');