multer
multer copied to clipboard
formData is not parser if not file is uploaded
Hi im having this problem with my nextjs app. I have an api route thas use the multer middleware, for that to work i have to tell next to disable the bodyparser for that route. In the fronted the from has a field for a file and other text fields. If i upload a file then i get all the data, the file and the text fields in the req.body. But if i dont upload a file then the text fields are not populated.
uploadRoute('imageFile', async (req, res) => {
console.info('REQ', req);
and that uploadRoute middleware im using is here:
import multer from 'multer';
const uploader = multer();
export default (fieldName, handler) => {
// manejar cuando no se usa fieldName
if (typeof fieldName !== 'string') {
handler = fieldName;
fieldName = 'files';
}
const uploadStrategy = uploader.array(fieldName);
return (req, res) => {
uploadStrategy(req, res, () => handler(req, res));
};
};
I'm having this issue too. Just an upvote here
This should work, and this test seems to cover it:
https://github.com/expressjs/multer/blob/4f4326a6687635411a69d70f954f48abb4bce58a/test/none.js#L33-L46
Are you still submitting the form as multipart/form-data
?