DoesNode.js have built-in Base64 encoding?
const uploadimage = asyncHandler(async(req, res, next) => { try{ var matches = req.body.base64image.match(/^data:([A-Za-z-+/]+);base64,(.+)$/); response = {}; if(matches.length !== 3){ return new Error('Invalid input string'); }
response.type = matches[1];
response.data = new Buffer(matches[2], 'base64');
let decodedImg = response;
let imageBuffer = descodedImg.data;
let type = decodedImg.type;
let extension = mime.extension(type);
let fileName = "image." + extension;
fs.writeFileSync("uploads" + fileName, imageBuffer, 'utf8');
return res.send({
"status":"success"
})
}catch(e){
return res.send({
"status":"failed",
})
}
});
but this error appears
DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use
node --trace-deprecation ...
to show where the warning was created)