File tree Expand file tree Collapse file tree
assets/core/ts/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -234,18 +234,35 @@ export const fileUploader = (props: FileUploaderProps = defaultProps) => ({
234234
235235 if ( this . multiple ) {
236236 const mergedFiles = this . mergeFileLists ( this . selectedFiles , validFiles ) ;
237+ const totalFileSize = mergedFiles . reduce ( ( total , current ) => {
238+ if ( typeof current === 'string' ) {
239+ return 0 ;
240+ }
241+ return total + Math . round ( Number ( current ?. size ) || 0 ) ;
242+ } , 0 ) ;
237243
238244 if ( this . maxFiles && mergedFiles . length > this . maxFiles ) {
239245 this . showError (
240246 sprintf (
241- // translators: %d is the maximum number of files allowed
247+ // translators: %d is the maximum number of files allowed.
242248 __ ( 'Cannot select more than %d files' , 'tutor' ) ,
243249 this . maxFiles ,
244250 ) ,
245251 ) ;
246252 return ;
247253 }
248254
255+ if ( totalFileSize > this . maxSize ) {
256+ this . showError (
257+ sprintf (
258+ // translators: %1$s is the maximum allowed size.
259+ __ ( 'Maximum allowed size is %1$s.' , 'tutor' ) ,
260+ formatBytes ( this . maxSize ) ,
261+ ) ,
262+ ) ;
263+ return ;
264+ }
265+
249266 this . selectedFiles = mergedFiles ;
250267 } else {
251268 this . selectedFiles = [ validFiles [ 0 ] ] ;
You can’t perform that action at this time.
0 commit comments