I'm trying to write a canvas data with node.js fs.writeFile
as a binary. JPEG file, but after the file is written I can see that the file is stored as plain text, not binary data.
This is an example of the data
sent from the client to my node, representing the JPEG image data (just a few first characters):
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAFA3PEY8MlBGQUZaVVBfeM...
I'm getting this data
on the client side by performing:
canvas.toDataURL('image/jpeg', 0.5).replace('data:image/jpeg;base64,', '')
Here is the function usage in my node.js server:
fs.writeFile('../some.jpeg', data, 'binary', function(err){});
Instead of the file being written as binary (״״ JFIF ...
), it writes exactly the data it received from the client.
What am I doing wrong here?