gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:52:08 25 4
gpt4 key购买 nike

来自 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com