Prevent adding of same file already present in the queue #719

Open
opened 2017-03-31 09:34:16 +00:00 by sahil1989 · 2 comments
sahil1989 commented 2017-03-31 09:34:16 +00:00 (Migrated from github.com)

There doesn't seem to be any solution available, from preventing the addition of a file already present in the queue.

There doesn't seem to be any solution available, from preventing the addition of a file already present in the queue.
jesus-novologic commented 2017-07-17 17:44:37 +00:00 (Migrated from github.com)

Wow, I have the same issue, and nobody answered it

Wow, I have the same issue, and nobody answered it
DzmVasileusky commented 2018-05-25 08:25:04 +00:00 (Migrated from github.com)

Well, you can check file hash on onAfterAddingFile.
A proper way will be to get MD5 hash but you can do more simple and less reliable hash function, like that.

getFileHash (file: File): string {

    return `${file.lastModifiedDate}${file.name}${file.size}`;

}

and then just check

fileHashes: string[] = [];
...
this.uploader.onAfterAddingFile = (newItem) => {

    const hash = this.getFileHash(newItem._file);

    // prevent dupes
    if (this.fileHashes.indexOf(hash) !== -1) {

        this.fileHashes.push(hash);

    } else {

        this.uploader.removeFromQueue(newItem);

    }

}
Well, you can check file hash on `onAfterAddingFile`. A proper way will be to get MD5 hash but you can do more simple and less reliable hash function, like that. ``` getFileHash (file: File): string { return `${file.lastModifiedDate}${file.name}${file.size}`; } ``` and then just check ``` fileHashes: string[] = []; ... this.uploader.onAfterAddingFile = (newItem) => { const hash = this.getFileHash(newItem._file); // prevent dupes if (this.fileHashes.indexOf(hash) !== -1) { this.fileHashes.push(hash); } else { this.uploader.removeFromQueue(newItem); } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#719