user2888686
user2888686

Reputation: 667

How to get file name when using express.bodyParser

When I use this module app.use(express.bodyParser({ keepExtensions: true, uploadDir: __dirname + "/public/adminupload" }));.My files are uploaded to __dirname + "/public/adminupload" directory but the file name is change randomly, new name is differently with req.files.file.name. So how can I get the new name?

Upvotes: 1

Views: 2798

Answers (1)

user568109
user568109

Reputation: 48003

You can get entire path from req.files.file.path. You can extract the filename like this:

path = require('path')
console.log(path.basename(req.files.file.path));

Upvotes: 1

Related Questions