Dropzone:阻止上传重复文件 [英] Dropzone: prevent uploading of duplicate files

查看:499
本文介绍了Dropzone:阻止上传重复文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Dropzone。我想阻止在Dropzone面板中上传已经作为缩略图存在的文件。上传时,我的意思是不允许在面板中显示两次具有相同名称的文件。我不关心服务器中已经存在的文件的情况,也没有在面板中显示,因为它将由具有相同名称的新文件替换。

I am using Dropzone. I'd like to prevent the uploading of a file which already exists as thumbnail in Dropzone "panel". With uploading I mean not to allow a file with the same name to be shown twice in the panel. I do not care about the case of the file already existing in the server and not showing in the panel, since it will be replaced by the new one with the same name.

尽管我付出了努力,但我无法找到如何实现这一目标。我很感激你的帮助。

I cannot find how to achieve that despite my efforts. I'd appreciate your help.

非常感谢

推荐答案

添加以下简单的代码行:

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);
            }
        }
    }
});

这篇关于Dropzone:阻止上传重复文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆