Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LIMIT_UNEXPECTED_FILE issue when using Dropzone uploading multiple files with node multer

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?

like image 733
Yujun Wu Avatar asked Sep 27 '22 06:09

Yujun Wu


1 Answers

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

<input type="file" name="files" />
like image 78
LeonidPelyhivskyi Avatar answered Nov 14 '22 04:11

LeonidPelyhivskyi