How to limit the number of dropzone.js files uploaded?

前端 未结 13 1352
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 04:28

Depending on the use case, how do I constrain the number of files that dropzone.js will allow?

For example, I might need to only allow 1, 2, or 4 files uploaded.

13条回答
  •  渐次进展
    2020-11-28 04:42

    maxFiles: 1 does the job but if you also want to remove the additional files you can use this sample code taken from the Wiki page:

    How can I limit the number of files?

    You're in luck! Starting with 3.7.0 Dropzone supports the maxFiles option. Simply set it to the desired quantity and you're good to go. If you don't want the rejected files to be viewed, simply register for the maxfilesexceeded event, and remove the file immediately:

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

提交回复
热议问题