Ask Your Question
3

Is it impossible to upload several files using multer in nodejs?

asked 2023-07-18 09:06:34 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-18 09:33:02 +0000

lakamha gravatar image

No, it is possible to upload several files using multer in Node.js. Multer allows you to specify a field name in the request body, which can be an array of files. You can then use the array method of Multer to process the array of files. Here is an example:

const multer = require('multer');
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname)
  }
});

const upload = multer({ storage: storage }).array('files');

app.post('/upload', function (req, res) {
  upload(req, res, function (err) {
    if (err) {
      // Handle the error
    } else {
      // Do something with the files
      res.send('Files uploaded successfully');
    }
  });
});

In this example, we are using the array method of Multer to handle an array of files with the field name files. The files will be stored in the uploads folder on the server.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-18 09:06:34 +0000

Seen: 9 times

Last updated: Jul 18 '23