Nodejs datauri to file

PHOTO EMBED

Fri Dec 16 2022 11:40:26 GMT+0000 (Coordinated Universal Time)

Saved by @swina #nodejs #datauri

const dataUri = 'data:image/png;base64,iVBORw0KGg...';

const matches = dataUri.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
const type = matches[1];
const buffer = new Buffer.from(matches[2], 'base64');

fs.writeFileSync('image.png', buffer, { encoding: 'base64' });
content_copyCOPY