Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added upload abort/cancel support #225

Merged
merged 2 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
private _xhr: XMLHttpRequest | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove private here please?

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 @@ -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);
Expand Down