如果qeue上只有至少10个文件,如何设置dropzone上传?

时间:2015-11-18 06:37:00

标签: limit dropzone.js minimum

如果qeue上只有至少10个文件,如何设置dropzone上传?

我已将autoProcessQueue设置为false,因此当单击提交按钮时,将运行一个fucntion来检查qeued文件。如果它们小于或大于10,则不会进行上传。

我如何实现这一目标? 请协助。

我在谷歌的各个地方都搜索过,但似乎无法找到答案。 。请帮忙!

这是我的代码..

<html>

<head>
<title></title>
<script src="ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">   </script>
<link href="css/basic.css" rel="stylesheet" type="text/css" />
</head>


<body>
<form role= "form"></form>
<button id="submit-all">Submit all files</button>
</body>

<script>
Dropzone.options.myDropzone = {

// Prevents Dropzone from uploading dropped files immediately
autoProcessQueue: false,

init: function() {
var submitButton = document.querySelector("#submit-all")
myDropzone = this; // closure

submitButton.addEventListener("click", function() {

myDropzone.processQueue(); // Tell Dropzone to process all queued files.



});

myDropzone.on("maxfilesexceeded", function(file) { this.removeFile(file); });


// You might want to show the submit button only when 
// files are dropped here:
this.on("addedfile", function() {
// Show submit button here and/or inform user to click it.
});

}
};
</script>
</html>

1 个答案:

答案 0 :(得分:2)

您可以使用dropzone中的getQueuedFiles()方法在init函数中完成此操作:

Dropzone.autoDiscover = false;

Dropzone.options.myDropzone = {
    autoProcessQueue: false,
    init: function () {
        var submitButton = document.querySelector("#submit-all");
        myDropzone = this;
        submitButton.addEventListener("click", function () {
            if (myDropzone.getQueuedFiles().length >= 10) { 
                myDropzone.processQueue();
            }
            else {
                alert("Not enough files!");
            }
        });
    }
};

var myDropzone = new Dropzone('form#my-dropzone');