@@ -22,18 +22,21 @@ export class NgUploaderService {
2222 subs : { id : string , sub : Subscription } [ ] ;
2323 contentTypes : string [ ] ;
2424 maxUploads : number ;
25+ maxFileSize : number ;
2526
2627 constructor (
2728 concurrency : number = Number . POSITIVE_INFINITY ,
2829 contentTypes : string [ ] = [ '*' ] ,
29- maxUploads : number = Number . POSITIVE_INFINITY
30+ maxUploads : number = Number . POSITIVE_INFINITY ,
31+ maxFileSize : number = Number . POSITIVE_INFINITY
3032 ) {
3133 this . queue = [ ] ;
3234 this . serviceEvents = new EventEmitter < UploadOutput > ( ) ;
3335 this . uploadScheduler = new Subject ( ) ;
3436 this . subs = [ ] ;
3537 this . contentTypes = contentTypes ;
3638 this . maxUploads = maxUploads ;
39+ this . maxFileSize = maxFileSize ;
3740
3841 this . uploadScheduler
3942 . pipe (
@@ -45,7 +48,7 @@ export class NgUploaderService {
4548 handleFiles ( incomingFiles : FileList ) : void {
4649 const allowedIncomingFiles : File [ ] = [ ] . reduce . call ( incomingFiles , ( acc : File [ ] , checkFile : File , i : number ) => {
4750 const futureQueueLength = acc . length + this . queue . length + 1 ;
48- if ( this . isContentTypeAllowed ( checkFile . type ) && futureQueueLength <= this . maxUploads ) {
51+ if ( this . isContentTypeAllowed ( checkFile . type ) && futureQueueLength <= this . maxUploads && this . isFileSizeAllowed ( checkFile . size ) ) {
4952 acc = acc . concat ( checkFile ) ;
5053 } else {
5154 const rejectedFile : UploadFile = this . makeUploadFile ( checkFile , i ) ;
@@ -291,6 +294,13 @@ export class NgUploaderService {
291294 return this . contentTypes . find ( ( type : string ) => type === mimetype ) !== undefined ;
292295 }
293296
297+ isFileSizeAllowed ( fileSize : number ) : boolean {
298+ if ( ! this . maxFileSize ) {
299+ return true ;
300+ }
301+ return fileSize <= this . maxFileSize ;
302+ }
303+
294304 makeUploadFile ( file : File , index : number ) : UploadFile {
295305 return {
296306 fileIndex : index ,
0 commit comments