@@ -4,9 +4,9 @@ import _ from 'lodash'
44( function ( ) {
55 'use strict'
66
7- angular . module ( 'tcUIComponents' ) . directive ( 'tcFileInput' , [ '$timeout' , tcFileInput ] )
7+ angular . module ( 'tcUIComponents' ) . directive ( 'tcFileInput' , [ '$timeout' , 'Helpers' , 'logger' , tcFileInput ] )
88
9- function tcFileInput ( $timeout ) {
9+ function tcFileInput ( $timeout , Helpers , logger ) {
1010 return {
1111 restrict : 'E' ,
1212 require : '^form' ,
@@ -26,14 +26,6 @@ import _ from 'lodash'
2626 scope . selectFile = selectFile
2727 var fileTypes = scope . fileType . split ( ',' )
2828
29- // Add extra checks for Windows zip file types
30- var hasZip = _ . some ( fileTypes , _ . matches ( 'zip' ) )
31-
32- if ( hasZip ) {
33- fileTypes = angular . copy ( fileTypes )
34- fileTypes . push ( 'x-zip' , 'x-zip-compressed' )
35- }
36-
3729 // fieldId is not set on element at this point, so grabbing with class .none
3830 // which exists on the element right away
3931 var fileInput = $ ( element [ 0 ] ) . find ( '.none' )
@@ -49,10 +41,16 @@ import _ from 'lodash'
4941 }
5042
5143 var fileSize = file . size
52- var isAllowedFileSize = fileSize < '524288000'
44+ var fileExtension = file . name . slice ( file . name . lastIndexOf ( '.' ) + 1 )
5345
54- var selectedFileType = file . type . slice ( file . type . lastIndexOf ( '/' ) + 1 )
55- var isAllowedFileFormat = _ . some ( fileTypes , _ . matches ( selectedFileType ) )
46+ var isAllowedFileSize = fileSize < '524288000'
47+ var isAllowedFileExt = _ . some ( fileTypes , _ . matches ( fileExtension ) )
48+ var isAllowedMIMEType = Helpers . isValidMIMEType ( file . type , fileExtension )
49+ var isAllowedFileFormat = isAllowedFileExt && isAllowedMIMEType
50+
51+ if ( file && ! isAllowedFileFormat ) {
52+ logger . error ( `Invalid file. Allowed extensions: ${ scope . fileType } . Recieved file extension ${ fileExtension } with MIME type ${ file . type } and file size ${ fileSize } ` )
53+ }
5654
5755 // Timeout needed for fixing IE bug ($apply already in progress)
5856 $timeout ( function ( ) {
0 commit comments