W
W
Wasya UK2017-04-14 20:44:56
JavaScript
Wasya UK, 2017-04-14 20:44:56

How to get the name of the file written by it in npm Multer?

When saving an image, the module adds its own unique code.

var multer = require('multer'),
    storage = multer.diskStorage({
        destination: function(req, file, callback) {
            callback(null, __dirname + '/public/tmp/upload_avatars');
        },
        filename: function(req, file, callback) {
            callback(null, file.originalname);
        }
    }),
    upload = multer({ storage: storage });

When I receive a request, the file is saved in a folder already with a unique ID.
app.post('/upload-image', upload.any(), function(req, res) {
...

How to get this unique name to write to the database? Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2017-04-14
@werty1001

It seems like there req.filesshould be an array of files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question