最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - LIMIT_UNEXPECTED_FILE issue when using Dropzone uploading multiple files with node multer - Stack Overflow

programmeradmin3浏览0评论

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 0
Add a ment  | 

3 Answers 3

Reset to default 2

In 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))

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论