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");
关注我的公众号