jquery dropzone.js with duplicate file checking using md5

0

If you use a simple check in the "addedfile" event of the dropzone component, it works normally by sending a file, or by adding multiple files one at a time and also selecting multiple and sending at once.

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())
                {
                    alert('O arquivo ' + file.name + ' já foi enviado');
                    this.removeFile(file);
                }
            }
        }
    });

But when trying to implement using md5 to check the files it works if sending only one file, or sending one by one, but if multiple select and send at once does not work.

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
            {
                /**
                 * Cria um hash do arquivo e compara
                 */
                var reader = new FileReader();
                reader.readAsBinaryString(this.files[_i]);
                reader.onload = function () {
                    var hash = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(btoa(reader.result)));
                    var reader2 = new FileReader();
                    reader2.readAsBinaryString(file);
                    reader2.onload = function () {
                        var hash2 = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(btoa(reader2.result)));
                        if (hash.toString() === hash2.toString()) {
                            alert('O arquivo ' + file.name + ' já adicionado foi na lista');
                            myDropzone.removeFile(file);
                        }
                    };
                };
            }
        }
    });

I wanted to check for duplicate files using md5.

    
asked by anonymous 10.05.2017 / 14:49

1 answer

0

The process for verifying using md5 is very time consuming, so check the size first and then use md5.

    
08.09.2017 / 21:33