From b074f80f076937c6efce17a212ed44ae127cfef0 Mon Sep 17 00:00:00 2001 From: lukasz-galka Date: Thu, 23 Feb 2017 16:58:15 +0100 Subject: [PATCH] handle maxUploads option #96 (#218) --- src/classes/upload-rejected.class.ts | 1 + src/directives/ng-file-select.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/classes/upload-rejected.class.ts b/src/classes/upload-rejected.class.ts index e8376956..dc40f801 100644 --- a/src/classes/upload-rejected.class.ts +++ b/src/classes/upload-rejected.class.ts @@ -1,6 +1,7 @@ export class UploadRejected { public static get EXTENSION_NOT_ALLOWED(): string { return 'ExtensionNotAllowed'; } public static get MAX_SIZE_EXCEEDED(): string { return 'MaxSizeExceeded'; } + public static get MAX_UPLOADS_EXCEEDED(): string { return 'MaxUploadsExceeded'; } file: any; reason: string; diff --git a/src/directives/ng-file-select.ts b/src/directives/ng-file-select.ts index c5f75e65..506eaaaa 100644 --- a/src/directives/ng-file-select.ts +++ b/src/directives/ng-file-select.ts @@ -102,6 +102,11 @@ export class NgFileSelectDirective implements OnChanges { }); } + if(this.options.maxUploads > 0 && this.files.length > this.options.maxUploads) { + this.onUploadRejected.emit({file: this.files.pop(), reason: UploadRejected.MAX_UPLOADS_EXCEEDED}); + this.files = []; + } + if (this.files && this.files.length) { this.uploader.addFilesToQueue(this.files); }