From 4d3d1ada8dac04f875e1923b6754061767b0df76 Mon Sep 17 00:00:00 2001 From: Eugene Voloshchak Date: Sat, 20 Aug 2022 16:40:20 +0300 Subject: [PATCH] Add file extension to filename if it does not have one --- src/components/AttachmentPicker/index.native.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index f67db30564a4..418be07b819f 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -7,6 +7,7 @@ import {Alert, Linking, View} from 'react-native'; import {launchImageLibrary} from 'react-native-image-picker'; import RNDocumentPicker from 'react-native-document-picker'; import RNFetchBlob from 'react-native-blob-util'; +import Str from 'expensify-common/lib/str'; import {propTypes as basePropTypes, defaultProps} from './attachmentPickerPropTypes'; import styles from '../../styles/styles'; import Popover from '../Popover'; @@ -65,8 +66,13 @@ const documentPickerOptions = { * @return {Promise} */ function getDataForUpload(fileData) { + let fileName = fileData.fileName || fileData.name || 'chat_attachment'; + const fileExtension = `.${_.last(fileData.type.split('/'))}`; + if (!Str.endsWith(fileName, fileExtension)) { + fileName = `${fileName}${fileExtension}`; + } const fileResult = { - name: fileData.fileName || fileData.name || 'chat_attachment', + name: fileName, type: fileData.type, uri: fileData.fileCopyUri || fileData.uri, size: fileData.fileSize || fileData.size,