问题描述
我想使用Dropzone.js,以便用户可以选择要上传的图像.但是我不希望它们被动态上传,而只是被添加到表单中,然后以常规方式提交到表单数组中.我该怎么办?
I want to use Dropzone.js so that the user can select images he wants to upload. But I do not want them to be uploaded on the fly, rather to just be added to form and then submitted the normal way in form array. How can I do that?
我见过类似,但是我根本不需要上传它们,我希望Dropzone将文件添加到表单中.
I've seen questions like How to get Dropzone.js to upload files only when a submit button is clicked?, but I do not need to upload them at all, I want Dropzone to add files to my form.
顺便说一句,如果重要的话,dropzone在div中,而不是完整形式.
BTW, dropzone is in div, not on whole form, if it is important.
有可能吗?
推荐答案
初始化Dropzone实例时,需要将 autoQueue 属性设置为false:
You need to set the autoQueue property to false when you initialize your dropzone instance:
var formData = new FormData();
//On addedfile:
Dropzone.options.myAwesomeDropzone = {
autoQueue: false,
init: function() {
this.on("addedfile", function(file) {
formData.append("file", file);
});
}
};
//On removedfile:
Dropzone.options.myAwesomeDropzone = {
init: function() {
this.on("removedfile", function(file) {
formData.delete('file');
});
}
};
这篇关于将Dropzone中的文件添加到表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!