Skip to content

Commit

Permalink
added upload abort/cancel support (bleenco#225)
Browse files Browse the repository at this point in the history
* added upload abort/cancel support

* make xhr property public
  • Loading branch information
marekszczepansky authored and jkuri committed Apr 10, 2017
1 parent c09d249 commit b538607
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/classes/uploaded-file.class.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class UploadedFile {
xhr: XMLHttpRequest | undefined;
id: string;
status: number;
statusText: string;
Expand All @@ -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;
Expand All @@ -34,6 +36,12 @@ export class UploadedFile {
this.speedAverageHumanized = null;
}

abortUpload(){
if (this.xhr) {
this.xhr.abort();
}
}

setProgress(progress: Object): void {
this.progress = progress;
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/ngx-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b538607

Please sign in to comment.