How can I save a base64-encoded image to disk?

My Express app is receiving a base64-encoded PNG from the browser (generated from canvas with toDataURL() ) and writing it to a file. But the file isn’t a valid image file, and the “file” utility simply identifies it as “data”. var body = req.rawBody, base64Data = body.replace(/^data:image\/png;base64,/,””), binaryData = new Buffer(base64Data, ‘base64’).toString(‘binary’); require(“fs”).writeFile(“out.png”, binaryData, “binary”, … Read more