ng2-file-upload icon indicating copy to clipboard operation
ng2-file-upload copied to clipboard

How do I cancel an upload of a file item .

Open SujaRaj opened this issue 6 years ago • 7 comments

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

SujaRaj avatar Mar 27 '18 14:03 SujaRaj

have you try throw new Error('error');

jdusenne avatar Mar 27 '18 15:03 jdusenne

It kind of worked although it was not passing in the error text to the on Failed method.

SujaRaj avatar Mar 27 '18 19:03 SujaRaj

@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.

koenvanderlinden avatar Mar 29 '18 13:03 koenvanderlinden

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.

djfuzzy avatar Mar 05 '20 20:03 djfuzzy

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

roddc avatar Feb 19 '21 09:02 roddc

fileItem.cancel() works for me with "ng2-file-upload": "1.4.0" . @roddc

silnose avatar Mar 04 '21 18:03 silnose

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(); };

info2ankit avatar Jul 01 '22 09:07 info2ankit