From e5fbb02896f2b5bc943f0dfb6d7bce4050352625 Mon Sep 17 00:00:00 2001 From: Marek Szczepansky Date: Tue, 28 Feb 2017 13:53:26 +0100 Subject: [PATCH 1/2] added upload abort/cancel support --- 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..be98af5a 100644 --- a/src/classes/uploaded-file.class.ts +++ b/src/classes/uploaded-file.class.ts @@ -1,4 +1,5 @@ export class UploadedFile { + private _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 e25c62db..8e34bbcc 100644 --- a/src/services/ngx-uploader.ts +++ b/src/services/ngx-uploader.ts @@ -47,7 +47,8 @@ export class NgUploaderService { let uploadingFile = new UploadedFile( this.generateRandomIndex(), file.name, - file.size + file.size, + xhr ); let queueIndex = this._queue.indexOf(file); From 90dbe581c04efe35fe9fc333e8c5b2ade4f068f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Szczepa=C5=84ski?= Date: Mon, 10 Apr 2017 23:37:49 +0200 Subject: [PATCH 2/2] make xhr property public --- src/classes/uploaded-file.class.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/classes/uploaded-file.class.ts b/src/classes/uploaded-file.class.ts index be98af5a..af0ef817 100644 --- a/src/classes/uploaded-file.class.ts +++ b/src/classes/uploaded-file.class.ts @@ -1,5 +1,5 @@ export class UploadedFile { - private _xhr: XMLHttpRequest | undefined; + xhr: XMLHttpRequest | undefined; id: string; status: number; statusText: string; @@ -16,7 +16,7 @@ export class UploadedFile { speedAverageHumanized: string|null; constructor(id: string, originalName: string, size: number, xhr?: XMLHttpRequest) { - this._xhr = xhr; + this.xhr = xhr; this.id = id; this.originalName = originalName; this.size = size; @@ -37,8 +37,8 @@ export class UploadedFile { } abortUpload(){ - if (this._xhr) { - this._xhr.abort(); + if (this.xhr) { + this.xhr.abort(); } }