LIMIT_UNEXPECTED_FILE issue when using Dropzone uploading multiple files with node multer
Asked Answered
P

3

6

Using Dropzone in the frontend to upload multiple files to the server in one request and using the Multer middleware to handle multipart/form-data. Set uploadMultiple: true in the Dropzone config, it will append [] to the name. For example, the name would be files[0], files1 etc.

The server side codes:

var uploader = multer({dest: dest});
router.post(url, uploader.array('files', 30), function(req, res) {
   ...
});

However, seems multer().array(fieldname) only allows the fieldname matches the name in the form data. Otherwise, it throws LIMIT_UNEXPECTED_FILE error.

Any suggestions to fix it by making the name always as 'fields' instead of appending [] or making the multer to handle different names like that?

Provence answered 6/11, 2015 at 15:13 Comment(0)
M
2

In your cases input attribute name on client side must be "files".

<input type="file" name="files" />
Murderous answered 19/1, 2017 at 13:43 Comment(0)
M
2

Under the Dropzone configuration, set paramName to a function that returns the name:

Dropzone.options.mainDropzone = {
    autoProcessQueue: false,
    uploadMultiple: true,
    paramName: function(){
        return "files";
    },
    previewsContainer: ".dropzone-previews"
}

Make sure to use the same name that the function returns on the server side:

var upload = multer({
    storage: Storage
}).array('files', 3);
Mckenna answered 22/1, 2020 at 23:4 Comment(0)
M
0

This worked for me

files.map(file => formData.append(files, file))

Milt answered 25/3, 2021 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.