I'm trying to make sure the uploaded file is an image, while using multer to handle the file upload.
The fileFilter
function takes the form of the following:
var fileType = require('file-type');
fileFilter: function(req, file, cb){
// Check filetype based on file content
var filetype = fileType(// File buffer here);
// Callback - file OK
cb(null, true)
}
The problem is file
only contains the following:
{ fieldname: 'photo',
originalname: 'photo.png',
encoding: '7bit',
mimetype: 'image/png' }
Is there a way to actually get the file's content (Buffer) in the fileFilter function so that I can inspect the file's content to determine its type?
edit: If this can be done using busboy
(the module multer uses), I'd be open to a solution that involves that.