Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eVoloshchak Can you please help me understand this

Why can't we always fileName = fileName + fileExtenstion ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eVoloshchak Can you please help me understand this
Why can't we always fileName = fileName + fileExtenstion ?

Because this bug is present only on Android. On iOS files have their real name with an extension, so that would produce something like file-42.mp4.mp4

@rushatgabhane rushatgabhane Aug 22, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, makes sense.

I know that this is a really edge edge case -

I renamed a file to some-video.mp4.mp4.
On selecting this file, the attachment picker's header shows some-video.mp4.mp4.mp4

Platform: Android

}
const fileResult = {
name: fileData.fileName || fileData.name || 'chat_attachment',
name: fileName,
type: fileData.type,
uri: fileData.fileCopyUri || fileData.uri,
size: fileData.fileSize || fileData.size,
Expand Down