nolags nolags - 11 months ago 91
Node.js Question

show filenames of file upload with console.log(req.files)

I have a file upload with node js and multer and want to show the names of the uploaded files in the terminal. But I only get

Selected Files: [object Object],[object Object],[object Object]'/upload', function(req,res){
upload(req,res,function(err) {
console.log('Selected Files: ' + req.files);
res.end("Error: '" + err + "'");
console.log('Files uploaded!');

I also tried req.files.filename but it gave me the output:
Selected Files: undefined

How can I show the names of the uploaded files?

Answer Source

you can change

console.log('Selected Files: ' + req.files);


console.log('Selected Files: ', req.files);

Modern Browsers are able to display the data right.


If you only want the file names it´s not possible without collecting all the file names with one function and then print that out for example:

var fileNames = [];

console.log('Selected Files: ', fileNames);