admin管理员组文章数量:1356447
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))
本文标签:
版权声明:本文标题:javascript - LIMIT_UNEXPECTED_FILE issue when using Dropzone uploading multiple files with node multer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743961044a2569033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论