Reputation: 397
I want to get the file original name from this app.post (used with multer):
app.post('/', upload.array('file'), function(req, res){
console.log(req.files);
res.status(204).end();
});
Using console.log(req.files)
I get:
[ { fieldname: 'file',
originalname: 'TSy16rd913.jpg',
encoding: '7bit',
mimetype: 'image/jpeg',
destination: './public/uploads/',
filename: 'TSy16rd913.jpg',
path: 'public/uploads/TSy16rd913.jpg',
size: 110736 } ]
Using console.log(req.files.originalname)
or console.log(req.files.filename)
gives undefined
.
So how do I get originalname or filename?
Upvotes: 0
Views: 4199
Reputation: 1392
As @Roland Starke answer, req.files
is an array, so you have to do something like this
req.files[0].filename
To get all filenames :
req.files.forEach(function(value, key) {
console.log(value.filename)
})
Upvotes: 4