Skip to content
Merged
Changes from all commits
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
21 changes: 19 additions & 2 deletions src/app/components/fileupload/fileupload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe

public uploadedFiles = [];

private fileUploadSubcription: Subscription;

constructor(
@Inject(DOCUMENT) private document: Document,
@Inject(PLATFORM_ID) private platformId: any,
Expand Down Expand Up @@ -746,7 +748,10 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
formData.append(this.name!, this.files[i], this.files[i].name);
}

this.http
// If the previous upload hasn't been finished, it is aborted.
this.cancelUploadRequest();

this.fileUploadSubcription = this.http
.request(<string>this.method, this.url as string, {
body: formData,
headers: this.headers,
Expand Down Expand Up @@ -805,6 +810,7 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
clear() {
this.files = [];
this.uploadedFileCount = 0;
this.cancelUploadRequest();
this.onClear.emit();
this.clearInputElement();
this.cd.markForCheck();
Expand All @@ -816,6 +822,7 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
* @group Method
*/
remove(event: Event, index: number) {
this.cancelUploadRequest();
this.clearInputElement();
this.onRemove.emit({ originalEvent: event, file: this.files[index] });
this.files.splice(index, 1);
Expand All @@ -826,12 +833,22 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
* @param {Number} index - Index of the file to be removed.
* @group Method
*/
removeUploadedFile(index) {
removeUploadedFile(index) {
let removedFile = this.uploadedFiles.splice(index, 1)[0];
this.uploadedFiles = [...this.uploadedFiles];
this.onRemoveUploadedFile.emit({ file: removedFile, files: this.uploadedFiles });
}

/**
* Cancel upload file request.
* */
cancelUploadRequest() {
if (this.fileUploadSubcription) {
this.fileUploadSubcription.unsubscribe();
this.fileUploadSubcription = undefined;
}
}

isFileLimitExceeded() {
const isAutoMode = this.auto;
const totalFileCount = isAutoMode ? this.files.length : this.files.length + this.uploadedFileCount;
Expand Down