Nodejs base64转存为图片

原创
前端路迹
2022-10-20 09:48
编辑于 2022-10-20 10:00

替换 base64头,writeFile 指定编码为 base64


var content = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAA......"

const ext = content.match(/^data:image\/(\w+)\+?\w*;base64,/);

const imgPath = 'tempimg.' + ext[1]

fs.writeFileSync(imgPath, content.replace(/^data:image\/\w+;base64,/, ""), "base64");
转载请注明出处。本文地址: https://www.qinshenxue.com/article/nodejs-base64-to-image.html
关注我的公众号