Created
September 30, 2017 16:37
-
-
Save ClementParis016/af453e7236bffaeabc6e3bc10a56fa7c to your computer and use it in GitHub Desktop.
Convert a base64 image to a file with Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const rawBase64 = ''; // typically 'data:image/png;base64,.......' | |
const [, ext, data] = rawBase64.match(/^data:image\/([a-z]+);base64,(.*)$/); | |
fs.writeFileSync(`image.${ext}`, data, 'base64'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment