What is the simplest way to encode PNG images to base64 using NodeJS? I need to store the presentation as a string in mongodb. The UI posts a mulitpart form and I can see the content being post correctly over the wire i.e;
Content-Disposition: form-data; name="userFile"; filename="Untitled2.png" Content-Type: image/png
Content-Type multipart/form-data; boundary=---------------------------71011331421746
Need to iterate through a file list and encode each file.
app.post('/api/upload', function (req, res) {
var thumbnails = [].concat(req.files.thumbnail);
for (var x = 0; x < thumbnails.length; x++) {
taskItem.push({bin: new Buffer(thumbnails[x]).toString('base64')});
}
}
Any help is appreciated.
J