Reputation: 147
I try to get files.filename (multer multifile).
I upload 2 files ( 1 image and 1 video) upload is good. req.files.image and req.files.video have good values
console.log(req.files['image']);
console.log(req.files.video);
Values are good :
[ { fieldname: 'image',
originalname: 'TEST-CAMPVIDEO1',
encoding: '7bit',
mimetype: 'image/jpeg',
destination: '/media',
filename: 'TEST-CAMPVIDEO11558696888750.jpg',
path: '\\media\\TEST-CAMPVIDEO11558696888750.jpg',
size: 10271 } ]
[ { fieldname: 'video',
originalname: 'TEST-CAMPVIDEO1',
encoding: '7bit',
mimetype: 'video/mp4',
destination: '/media',
filename: 'TEST-CAMPVIDEO11558696888756.mp4',
path: '\\media\\TEST-CAMPVIDEO11558696888756.mp4',
size: 15535191 } ]
In node.js
but when i tried to get filename :
console.log(req.files['image']['filename']);
console.log(req.files.video.filename);
It returns undefined
Someone have an answer ???
Thanks friends :)
Upvotes: 0
Views: 1680
Reputation: 21
Try it will be work
let filesArray = [];
req.files.forEach(element => {
const file = {
filename: element.filename
}
filesArray.push(file);
});
multiple files uploads using multer
Upvotes: 0
Reputation: 1352
It looks like the result of req.files['image']
is an array. So you should, in this case, select the first and only item in it like this: req.files['image'][0].filename
and it should work.
The array does only contain objects, not the filename property. The first object in the array does have the filename property
Upvotes: 2