@@ -42,6 +42,7 @@ type Props = {
4242 clientName : string ,
4343 className : string ,
4444 chunked : boolean ,
45+ fileLimit : number ,
4546 onClose : Function ,
4647 onComplete : Function ,
4748 getLocalizedMessage : Function ,
@@ -57,17 +58,20 @@ type DefaultProps = {|
5758 chunked : boolean ,
5859 className : string ,
5960 clientName : string ,
61+ fileLimit : number ,
6062 uploadHost : string ,
6163 onClose : Function ,
6264 onComplete : Function
6365| } ;
6466
6567type State = {
6668 view : View ,
67- items : UploadItem [ ]
69+ items : UploadItem [ ] ,
70+ message : string
6871} ;
6972
7073const CHUNKED_UPLOAD_MIN_SIZE_BYTES = 52428800 ; // 50MB
74+ const FILE_LIMIT_DEFAULT = 100 ; // Upload at most 100 files at once by default
7175
7276class ContentUploader extends Component < DefaultProps , Props , State > {
7377 id : string ;
@@ -82,6 +86,7 @@ class ContentUploader extends Component<DefaultProps, Props, State> {
8286 chunked : true ,
8387 className : '' ,
8488 clientName : CLIENT_NAME_CONTENT_UPLOADER ,
89+ fileLimit : FILE_LIMIT_DEFAULT ,
8590 uploadHost : DEFAULT_HOSTNAME_UPLOAD ,
8691 onClose : noop ,
8792 onComplete : noop
@@ -98,7 +103,8 @@ class ContentUploader extends Component<DefaultProps, Props, State> {
98103 const { rootFolderId , token } = props ;
99104 this . state = {
100105 view : rootFolderId && token ? VIEW_UPLOAD_EMPTY : VIEW_ERROR ,
101- items : [ ]
106+ items : [ ] ,
107+ message : ''
102108 } ;
103109 this . id = uniqueid ( 'bcu_' ) ;
104110 }
@@ -162,7 +168,7 @@ class ContentUploader extends Component<DefaultProps, Props, State> {
162168 * @return {void }
163169 */
164170 addFilesToUploadQueue = ( files : File [ ] ) => {
165- const { chunked } = this . props ;
171+ const { chunked, fileLimit , getLocalizedMessage } = this . props ;
166172 const { view, items } = this . state ;
167173
168174 // Disable chunked upload in IE11 for now until hashing is done in a worker
@@ -207,7 +213,20 @@ class ContentUploader extends Component<DefaultProps, Props, State> {
207213 return uploadItem ;
208214 } ) ;
209215
210- this . updateViewAndCollection ( items . concat ( newItems ) ) ;
216+ let updatedItems = [ ] ;
217+ const totalNumOfItems = items . length + newItems . length ;
218+
219+ // Don't add more than fileLimit # of items
220+ if ( totalNumOfItems > fileLimit ) {
221+ updatedItems = items . concat ( newItems . slice ( 0 , fileLimit - items . length ) ) ;
222+ this . setState ( {
223+ message : getLocalizedMessage ( 'buik.upload.message.toomanyfiles' , { fileLimit } )
224+ } ) ;
225+ } else {
226+ updatedItems = items . concat ( newItems ) ;
227+ }
228+
229+ this . updateViewAndCollection ( updatedItems ) ;
211230
212231 // Automatically start upload if other files are being uploaded
213232 if ( view === VIEW_UPLOAD_IN_PROGRESS ) {
@@ -357,7 +376,7 @@ class ContentUploader extends Component<DefaultProps, Props, State> {
357376 } ;
358377
359378 /**
360- * Handles an upload error .
379+ * Handles an upload progress event .
361380 *
362381 * @private
363382 * @param {UploadItem } item - Upload item corresponding to progress event
@@ -409,7 +428,7 @@ class ContentUploader extends Component<DefaultProps, Props, State> {
409428 */
410429 render ( ) {
411430 const { onClose, getLocalizedMessage, className, measureRef, isTouch } : Props = this . props ;
412- const { view , items } : State = this . state ;
431+ const { view , items , message } : State = this . state ;
413432
414433 const hasFiles = items . length !== 0 ;
415434 const isLoading = items . some ( ( item ) => item . status === STATUS_IN_PROGRESS ) ;
@@ -431,6 +450,7 @@ class ContentUploader extends Component<DefaultProps, Props, State> {
431450 getLocalizedMessage = { getLocalizedMessage }
432451 hasFiles = { hasFiles }
433452 isLoading = { isLoading }
453+ message = { message }
434454 onCancel = { this . cancel }
435455 onClose = { onClose }
436456 onUpload = { this . upload }
0 commit comments