Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit da5e182

Browse files
author
Nick Litwin
committed
Add logging if file is not the correct format for the field
1 parent 12cf8a7 commit da5e182

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/directives/tc-file-input/tc-file-input.directive.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import _ from 'lodash'
44
(function() {
55
'use strict'
66

7-
angular.module('tcUIComponents').directive('tcFileInput', ['$timeout', 'Helpers', tcFileInput])
7+
angular.module('tcUIComponents').directive('tcFileInput', ['$timeout', 'Helpers', 'logger', tcFileInput])
88

9-
function tcFileInput($timeout, Helpers) {
9+
function tcFileInput($timeout, Helpers, logger) {
1010
return {
1111
restrict: 'E',
1212
require: '^form',
@@ -43,8 +43,14 @@ import _ from 'lodash'
4343
var fileSize = file.size
4444
var fileExtension = file.name.slice(file.name.lastIndexOf('.') + 1)
4545

46-
var isAllowedFileSize = fileSize < '524288000'
47-
var isAllowedFileFormat = _.some(fileTypes, _.matches(fileExtension)) && Helpers.isValidMIMEType(file.type, fileExtension)
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+
}
4854

4955
// Timeout needed for fixing IE bug ($apply already in progress)
5056
$timeout(function() {

0 commit comments

Comments
 (0)