From 52f4d7fd3295731864052568e120110203e09229 Mon Sep 17 00:00:00 2001 From: Jonathan McDill Date: Tue, 15 Aug 2017 13:01:09 -0400 Subject: [PATCH] Fix non-advancing index bug (duplicate upload error) --- src/ngx-uploader/classes/ngx-uploader.class.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ngx-uploader/classes/ngx-uploader.class.ts b/src/ngx-uploader/classes/ngx-uploader.class.ts index 14384370..db2e4e39 100644 --- a/src/ngx-uploader/classes/ngx-uploader.class.ts +++ b/src/ngx-uploader/classes/ngx-uploader.class.ts @@ -73,6 +73,10 @@ export function humanizeBytes(bytes: number): string { return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; } +export function toArray(files: FileList) { + return Array.prototype.slice.call(files || []); +} + export class NgUploaderService { fileList: FileList; files: UploadFile[]; @@ -85,8 +89,9 @@ export class NgUploaderService { } handleFiles(files: FileList): void { - this.fileList = files; + this.fileList = toArray(this.fileList).concat(toArray(files)); + let i = this.files.length; this.files.push(...[].map.call(files, (file: File, i: number) => { const uploadFile: UploadFile = { fileIndex: i, @@ -110,6 +115,7 @@ export class NgUploaderService { sub: Subscription, nativeFile: file }; + i = i + 1; this.serviceEvents.emit({ type: 'addedToQueue', file: uploadFile }); return uploadFile; @@ -268,7 +274,7 @@ export class NgUploaderService { const form = new FormData(); try { - const uploadFile = this.fileList.item(file.fileIndex); + const uploadFile = this.fileList[file.fileIndex]; const uploadIndex = this.files.findIndex(file => file.nativeFile === uploadFile); if (this.files[uploadIndex].progress.status === UploadStatus.Canceled) {