Skip to content

Commit

Permalink
Fix non-advancing index bug (duplicate upload error)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleosjo authored and jkuri committed Aug 15, 2017
1 parent 795b5f7 commit 52f4d7f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ngx-uploader/classes/ngx-uploader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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,
Expand All @@ -110,6 +115,7 @@ export class NgUploaderService {
sub: Subscription,
nativeFile: file
};
i = i + 1;

this.serviceEvents.emit({ type: 'addedToQueue', file: uploadFile });
return uploadFile;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 52f4d7f

Please sign in to comment.