In Expressjs I upload an image. It comes as a Buffer encoding 7bit:
{ fieldname: 'file',
originalname: 'img.JPG',
encoding: '7bit',
mimetype: 'image/jpeg',
buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 64 00 64 00 00 ff db 00 43 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 0
1 01 01 01 01 01 ... >,
size: 873066 }
How to save it as an image to a file system? Something is saved but it is not an image:
Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted of too large.
These do not work:
fs.writeFile('uploaded-img.jpg', req.file, 'ascii', function(err) {
fs.writeFile('uploaded-img.jpg', req.file.toString('ascii'), 'ascii', function(err) {