I'm encountering an issue while trying to upload multiple files to my server using multer
. Although I can access the req.files
array, I am unable to retrieve the buffer
property of the files. Upon attempting to log them with console.log
, all I get is undefined
.
This snippet shows my HTML (ejs) code:
<form method="post" action="/send" enctype="multipart/form-data">
<div class="row">
<div class="col">
<input type="file" multiple class="form-control" name="files">
</div>
<div class="col text-end">
<input type="submit" class="btn btn-primary w-100">
</div>
</div>
</form>
The route definition looks like this:
const express = require("express");
const router = express.Router();
const multer = require("multer");
const upload = multer({ dest: "uploads/" });
const indexController = require("../controllers/index.controller");
router.post("/send", upload.array("files", 5), indexController.send);
module.exports = router;
... now onto the controller:
exports.send = async (req, res) => {
...
console.log(req.files); // [ { fieldname: 'files', ..., size: 1576 } ]
console.log(req.files.map((f) => f.buffer)); // [ undefined ]
...
}
Any suggestions on how to access the .buffer
property of each file when dealing with multiple uploads? Your assistance is greatly appreciated.