multer icon indicating copy to clipboard operation
multer copied to clipboard

formData is not parser if not file is uploaded

Open Maxi-Di-Mito opened this issue 4 years ago • 2 comments

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));
    };
};

Maxi-Di-Mito avatar Jan 19 '21 16:01 Maxi-Di-Mito

I'm having this issue too. Just an upvote here

trsmarc avatar Aug 13 '22 19:08 trsmarc

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?

LinusU avatar Oct 11 '22 16:10 LinusU