node.js - 不能使用 dropzone 和 multer 进行多重上传

标签 node.js express dropzone.js multer

来自 dropzone.js:

If you have the option uploadMultiple set to true, then Dropzone will append [] to the name.

所以对于 multer,array('file') 不会工作,因为 fieldname: 'file[0]'

如果我上传多个文件,它将是 fieldname: 'file[0]' fieldname: 'file[1]' ....

我必须使用 upload.any(),有什么办法可以在 multer 中做一些上传后 Hook 吗?

最佳答案

请在下方使用

HTML:

<form action="/uploadImages" id="buldUploadForm" enctype="multipart/form-data" method="post">
    <div class="dropzone dz-clickable" id="uploadDropzone">
       <div class="dz-default dz-message" data-dz-message="">
          <span>Drop files here to upload</span>
       </div>
    </div>
    <br />
    <input type="submit" class="btn btn-primary" id="submitAllProcess" value="Upload Images" name="submit" />
</form>

JavaScript:

Dropzone.autoDiscover = false;

function paramNameForSend() {
   return "userParamName";
}

$(document).ready(function() {
  var myDropzone = new Dropzone("#uploadDropzone", {
    url: '/uploadImages',
    maxFilesize: 5, // MB
    maxFiles: 10,
    autoProcessQueue: false,
    uploadMultiple: true,
    paramName: paramNameForSend,
    method: 'post',
    parallelUploads: 10,
    init: function() {
        var myDropzone = this;

        $("#buldUploadForm").submit(function (e) {
            e.preventDefault();
            e.stopPropagation();
            myDropzone.processQueue();
        }); 
      }
    });
});

穆尔特:

var storage =   multer.diskStorage({
  destination: function (req, file, callback) {
    callback(null, './uploads');
  }
});

var uploadMultiple = multer({ storage : storage}).array('userParamName', 10);

关于node.js - 不能使用 dropzone 和 multer 进行多重上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35764981/

相关文章:

node.js - Nodejs、Forever 和 SystemD 启动问题

node.js - Express/node.js 路由器中的通配符

node.js - Node 快车 : how to only send custom error messages back to client

java - angularjs spring Rest文件上传表单

javascript - Dropzone js 不会触发 ajax 调用

node.js - 在不同的机器上运行客户端和服务器

node.js - 在 Express 中,为什么 .config() 中的 env 变量是可选的?

node.js - Node.js + Express.js 应用的错误处理原则?

javascript - 如何使用 nodeJS 从 JSON 对象中删除项目?

javascript - dropzone.js 从服务器检索时抑制进度条