How do I cancel an upload of a file item . #999

Open
opened 2018-03-27 14:21:48 +00:00 by SujaRaj · 7 comments
SujaRaj commented 2018-03-27 14:21:48 +00:00 (Migrated from github.com)

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

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
jdusenne commented 2018-03-27 15:42:58 +00:00 (Migrated from github.com)

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

have you try `throw new Error('error');`
SujaRaj commented 2018-03-27 19:41:42 +00:00 (Migrated from github.com)

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

It kind of worked although it was not passing in the error text to the on Failed method.
koenvanderlinden commented 2018-03-29 13:28:13 +00:00 (Migrated from github.com)

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

@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.
djfuzzy commented 2020-03-05 20:21:20 +00:00 (Migrated from github.com)

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.

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.
roddc commented 2021-02-19 09:20:56 +00:00 (Migrated from github.com)

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

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
silnose commented 2021-03-04 18:42:48 +00:00 (Migrated from github.com)

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

fileItem.cancel() works for me with "ng2-file-upload": "1.4.0" . @roddc
info2ankit commented 2022-07-01 09:11:09 +00:00 (Migrated from github.com)

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

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(); };`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#999