The code snippet below shows my current implementation:
import multer from "multer";
const upload = multer().single('file');
router.post('/add', async (req, res) => {
upload(req, res, async (err: any) => {
if (err) {
res.status(500).send(err.toString())
}
else {
res.status(200).send(await addMedia(req.file.filename))
}
})
});
I am currently in the process of determining the appropriate Error type to replace any
.
However, when I attempted to use MulterError
, I encountered the following error message :
Argument of type '(err: MulterError) => Promise' is not assignable to parameter of type 'NextFunction'. Types of parameters 'err' and 'deferToNext' are incompatible. Type 'string' is not assignable to type 'MulterError'.
Using unknown
is not feasible due to the .toString()
method. While string
does work, it does not accurately reflect the type, as further investigation reveals that a MulterError
is present.
An additional point of confusion lies with the 3rd parameter of the upload
function - this may possibly be contributing to my dilemma.