How do I cancel an upload of a file item . #999
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
How do I cancel an upload of a file item if conditions for a file are not met.
I want to manually cancel a file item upload .
I have tried all the below options
beforeFileUpload(fileItem: FileItem) {
if (fileItem.file.name =='xyz'){
this.uploader.cancelItem(fileItem);
fileItem.cancel();
fileItem.isCancel = true;
return;
}
None of these work. It still uploads the files.
I use version 1.3.0
Angular Cli 1.7.3
have you try
throw new Error('error');It kind of worked although it was not passing in the error text to the on Failed method.
@SujaRaj Based on your code sample you try to cancel the fileItem. Cancel should be used to cancel the upload process, when item is being uploaded.
As the eventname 'beforeFileUpload' suggests, it not yet uploading. So calling cancelItem does nothing.
Suggestion:
Use this.uploader.removeFromQueue(fileItem) to remove it from the queue.
Bringing this back from the dead. @koenvanderlinden, your suggestion doesn't work. I just want to be able to cancel the upload inside of the onBeforeUploadItem.
Is there any updates? I want to have a feature that users can cancel items that are waiting in the queue and retry them afterward
fileItem.cancel() works for me with "ng2-file-upload": "1.4.0" . @roddc
Allow user to upload file when file has no error.
<button type="button" class="btn btn-link p-0 mr-2" (click)="item.upload()" *ngIf="!item.isError"> <i class="fas fa-upload text-success"></i> </button>Now create error to the file when needed.
this.uploader.onAfterAddingFile = (fileItem: FileItem) => { fileItem.isError = true; this._cdr.detectChanges(); };