NodeJS writes base64 encoded image to file

I searched and tried all solutions in stackoverflow, but none of them work in my instance. Basically I have an image edited by html5 canvas, downloading from the client, and I need to save it to disk, but, unfortunately, I can not open the file that I just saved. (I am using Windows 7)

My code is:

var base64Data = req.body.image.replace(/^data:image\/(png|gif|jpeg);base64,/,'');
require('fs').writeFile('public/aboutToGiveUp.png', new Buffer(base64Data, 'base64'));
+4
source share
1 answer

Try to use. /public/aboutToGiveUp.png or make sure the path refers to a file containing this code.

0
source

Source: https://habr.com/ru/post/1625938/


All Articles