1 | initial version |
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.