Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropzone: prevent uploading of duplicate files

Tags:

javascript

php

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.

Thank you very much

like image 547
Unknown developer Avatar asked Oct 10 '14 09:10

Unknown developer


1 Answers

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);
            }
        }
    }
});
like image 161
Luca Perico Avatar answered Sep 18 '22 13:09

Luca Perico