Dropzone: prevent addfile twice

♀尐吖头ヾ 提交于 2019-12-06 08:34:44

Add these simple lines of code:

myDropzone.on("addedfile", function(file) {
    if (this.files.length) {
        var _i, _len;
        for (_i = 0, _len = this.files.length; _i < _len - 1; _i++) // -1 to exclude current file
        {
            if(this.files[_i].name === file.name && this.files[_i].size === file.size && this.files[_i].lastModifiedDate.toString() === file.lastModifiedDate.toString())
            {
                this.removeFile(file);
            }
        }
    }
});
tmarwen

Checking the file name and size should be fine. I already tested that and it had worked almost fine for me and haven't crossed any issues with it.

The original thread I landed in was a Git issue #639 where a community member posted his solution for name and size verification.

That trick was also mentioned in a similar post answer.

 this.on("addedfile", function (file) {
                    if (this.files.length) {
                        var i, len, pre;
                        for (i = 0, len = this.files.length; i < len - 1; i++) {
                            if (this.files[i].name == file.name) {
                                alert("The Doc.: " + file.name + " is already registered.")
                                return (pre = file.previewElement) != null ? pre.parentNode.removeChild(file.previewElement) : void 0;
                            }
                        }
                    }
                });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!