来自dropzone.js:
如果您将选项uploadMultiple设置为true,则Dropzone会将[]附加到名称。
所以对于multer,array('file')不会起作用,因为class Name {
private:
unsigned int array[];
public:
unsigned int getArray();
Name(unsigned int);
}
//I'm defining everything outside the class because I'm told that's good practice
unsigned int Name::getArray() {
return this->array;
}
//this is the problem
Name::Name(unsigned int length) {
this->array = new unsigned int [length];
}
如果我上传多个文件,则会fieldname: 'file[0]'
fieldname: 'file[0]'
....
我必须使用fieldname: 'file[1]'
,有没有办法在multer中做一些上传后挂钩?
答案 0 :(得分:1)
请使用以下
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();
});
}
});
});
MULTER:
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './uploads');
}
});
var uploadMultiple = multer({ storage : storage}).array('userParamName', 10);