From b538607607c18a19fec6f7a48ade604a0f0aa5dd Mon Sep 17 00:00:00 2001 From: Marek Szczepansky Date: Mon, 10 Apr 2017 23:39:16 +0200 Subject: [PATCH] added upload abort/cancel support (#225) * added upload abort/cancel support * make xhr property public --- src/classes/uploaded-file.class.ts | 10 +++++++++- src/services/ngx-uploader.ts | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/classes/uploaded-file.class.ts b/src/classes/uploaded-file.class.ts index 4f69e403..af0ef817 100644 --- a/src/classes/uploaded-file.class.ts +++ b/src/classes/uploaded-file.class.ts @@ -1,4 +1,5 @@ export class UploadedFile { + xhr: XMLHttpRequest | undefined; id: string; status: number; statusText: string; @@ -14,7 +15,8 @@ export class UploadedFile { speedAverage: number; speedAverageHumanized: string|null; - constructor(id: string, originalName: string, size: number) { + constructor(id: string, originalName: string, size: number, xhr?: XMLHttpRequest) { + this.xhr = xhr; this.id = id; this.originalName = originalName; this.size = size; @@ -34,6 +36,12 @@ export class UploadedFile { this.speedAverageHumanized = null; } + abortUpload(){ + if (this.xhr) { + this.xhr.abort(); + } + } + setProgress(progress: Object): void { this.progress = progress; } diff --git a/src/services/ngx-uploader.ts b/src/services/ngx-uploader.ts index 146097d4..a7167f28 100644 --- a/src/services/ngx-uploader.ts +++ b/src/services/ngx-uploader.ts @@ -50,7 +50,8 @@ export class NgUploaderService { let uploadingFile = new UploadedFile( this.generateRandomIndex(), file.name, - file.size + file.size, + xhr ); let queueIndex = this._queue.indexOf(file);