diff --git a/src/CONST.js b/src/CONST.js index 9d6f7dcf2a4c..cbf24bae5610 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -15,6 +15,9 @@ const CONST = { ANIMATION_IN_TIMING: 100, API_ATTACHMENT_VALIDATIONS: { + // Same as the PHP layer allows + ALLOWED_EXTENSIONS: ['jpg', 'jpeg', 'png', 'gif', 'pdf', 'html', 'txt', 'rtf', 'doc', 'docx', 'htm', 'tiff', 'tif', 'xml', 'mp3', 'mp4', 'mov'], + // 50 megabytes in bytes MAX_SIZE: 52428800, diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index bb79652e975c..4e0f31c53485 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -4,6 +4,7 @@ import {View, Animated, Keyboard} from 'react-native'; import Str from 'expensify-common/lib/str'; import lodashGet from 'lodash/get'; import lodashExtend from 'lodash/extend'; +import _ from 'underscore'; import CONST from '../CONST'; import Modal from './Modal'; import AttachmentView from './AttachmentView'; @@ -168,6 +169,17 @@ class AttachmentModal extends PureComponent { return false; } + const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(file, 'name', '')); + if (!_.contains(CONST.API_ATTACHMENT_VALIDATIONS.ALLOWED_EXTENSIONS, fileExtension.toLowerCase())) { + const invalidReason = `${this.props.translate('attachmentPicker.notAllowedExtension')} ${CONST.API_ATTACHMENT_VALIDATIONS.ALLOWED_EXTENSIONS.join(', ')}`; + this.setState({ + isAttachmentInvalid: true, + attachmentInvalidReasonTitle: this.props.translate('attachmentPicker.wrongFileType'), + attachmentInvalidReason: invalidReason, + }); + return false; + } + return true; }