不能使用 dropzone 和 multer 进行多重上传
can not multiple upload using dropzone and 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 中做一些 post-upload 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);
来自 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 中做一些 post-upload 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);