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?
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?
Share Improve this question asked Nov 6, 2015 at 15:13 Yujun WuYujun Wu 3,01212 gold badges41 silver badges56 bronze badges 03 Answers
Reset to default 2In your cases input attribute name on client side must be "files".
<input type="file" name="files" />
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);
This worked for me
files.map(file => formData.append(
files, file))