How to handle duplicate files while uploading from the queue? #733

Open
opened 2017-04-05 12:17:45 +00:00 by shakthi23 · 4 comments
shakthi23 commented 2017-04-05 12:17:45 +00:00 (Migrated from github.com)

How i can handle duplicate files while uploading, for example, if i want to remove an item from an array, then, i can use item.remove(), like wise, if want to check for duplicate files in queue and if want to handle duplicates.
Is there anything in this ng2-file-upload, please?

How i can handle duplicate files while uploading, for example, if i want to remove an item from an array, then, i can use item.remove(), like wise, if want to check for duplicate files in queue and if want to handle duplicates. Is there anything in this ng2-file-upload, please?
dannyk08 commented 2017-04-06 21:12:29 +00:00 (Migrated from github.com)

@shakthi23 you want to check the files queue and see if there are files with the same name

// this.fileInput: the queue that is awaiting to submit files

private checkDuplicateFiles(): boolean {
    let filesArray = this.fileInput.queue.map(item => item.file.name);
    return filesArray.some((item, index, array) => {
      return filesArray.indexOf(item) !== index;
    });
}

now when it comes to removing a single file you can just .splice the index of the duplicate file from the array

@shakthi23 you want to check the files queue and see if there are files with the same name ``` // this.fileInput: the queue that is awaiting to submit files private checkDuplicateFiles(): boolean { let filesArray = this.fileInput.queue.map(item => item.file.name); return filesArray.some((item, index, array) => { return filesArray.indexOf(item) !== index; }); } ``` now when it comes to removing a single file you can just `.splice` the index of the duplicate file from the array
dannyk08 commented 2017-04-06 21:15:31 +00:00 (Migrated from github.com)
other people are doing this too -> https://github.com/valor-software/ng2-file-upload/issues/609
sribala333 commented 2019-12-02 10:06:43 +00:00 (Migrated from github.com)

How i can handle duplicate files while uploading, for example, if i want to remove an item from an array, then, i can use item.remove(), like wise, if want to check for duplicate files in queue and if want to handle duplicates.
Is there anything in this ng2-file-upload, please?

you don't need ng2-file-upload . Just use this...
openUploadDoc(event) {
for (let i = 0; i < event.target.files.length; i++) {
if (this.bulkUploadDoc.length > 0 &&
this.bulkUploadDoc.some(x => x.fileName === event.target.files[i].name)) {
alert('file alraedy exist');
} else {
this.bulkUploadDoc.push(event.target.files[i]);
}
}
}

> How i can handle duplicate files while uploading, for example, if i want to remove an item from an array, then, i can use item.remove(), like wise, if want to check for duplicate files in queue and if want to handle duplicates. > Is there anything in this ng2-file-upload, please? you don't need ng2-file-upload . Just use this... openUploadDoc(event) { for (let i = 0; i < event.target.files.length; i++) { if (this.bulkUploadDoc.length > 0 && this.bulkUploadDoc.some(x => x.fileName === event.target.files[i].name)) { alert('file alraedy exist'); } else { this.bulkUploadDoc.push(event.target.files[i]); } } }
JonaaSosa commented 2020-06-18 11:56:15 +00:00 (Migrated from github.com)

this.uploader.onAfterAddingFile = (item) => {
item.remove();
if (this.uploader.queue.filter(f => f._file.name == item._file.name).length == 0) {
this.uploader.queue.push(item);
} else {
alert("file duplicated");
}
};

this.uploader.onAfterAddingFile = (item) => { item.remove(); if (this.uploader.queue.filter(f => f._file.name == item._file.name).length == 0) { this.uploader.queue.push(item); } else { alert("file duplicated"); } };
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#733