I'm getting the image data client-side (base64) from JavaScript via the FileReader() object, and then I post that data to the Node.JS/Express server and write an image via the following code:
fs.writeFile(__dirname+'/../resources/img/products/0.png', imageData, 'base64', function(err) {
if(err) return res.send({err: 'There was an error saving product image'});
res.send({});
});
but the image comes up as corrupt. A shortened version of the data looks like this:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZkAAAEpCAYAAABBb1+7AAAACXBIW…KxrrQ4WeEi84KFqYztjvTRlkNvrolLq7JzPEcwKtOIyP8PvUG8/X++RRoAAAAASUVORK5CYII=
Also, I split that data with (',') and only upload the [1] of the array, so only this part is sent to the server:
iVBORw0KGgoAAAANSUhEUgAAAZkAAAEpCAYAAABBb1+7AAAACXBIW…KxrrQ4WeEi84KFqYztjvTRlkNvrolLq7JzPEcwKtOIyP8PvUG8/X++RRoAAAAASUVORK5CYII=
EDIT: For the person who posted as possible dupe, using their code I get the variable 'matches' as null.