diff --git a/android/app/src/main/java/com/mattermost/helpers/RealPathUtil.java b/android/app/src/main/java/com/mattermost/helpers/RealPathUtil.java index a34bf3abb..ed651701c 100644 --- a/android/app/src/main/java/com/mattermost/helpers/RealPathUtil.java +++ b/android/app/src/main/java/com/mattermost/helpers/RealPathUtil.java @@ -73,7 +73,12 @@ public class RealPathUtil { split[1] }; - return getDataColumn(context, contentUri, selection, selectionArgs); + String name = getDataColumn(context, contentUri, selection, selectionArgs); + if (!TextUtils.isEmpty(name)) { + return name; + } + + return getPathFromSavingTempFile(context, uri); } } diff --git a/app/client/rest/files.ts b/app/client/rest/files.ts index b257e032c..cd665a637 100644 --- a/app/client/rest/files.ts +++ b/app/client/rest/files.ts @@ -55,7 +55,7 @@ const ClientFiles = (superclass: any) => class extends superclass { ); }; - uploadPostAttachment = async ( + uploadPostAttachment = ( file: FileInfo, channelId: string, onProgress: (fractionCompleted: number, bytesRead?: number | null | undefined) => void, diff --git a/app/managers/draft_upload_manager/index.ts b/app/managers/draft_upload_manager/index.ts index c353c0293..76d11764a 100644 --- a/app/managers/draft_upload_manager/index.ts +++ b/app/managers/draft_upload_manager/index.ts @@ -69,9 +69,10 @@ class DraftUploadManager { }; public cancel = (clientId: string) => { - const h = this.handlers[clientId]; - delete this.handlers[clientId]; - h?.cancel?.(); + if (this.handlers[clientId]?.cancel) { + this.handlers[clientId].cancel?.(); + delete this.handlers[clientId]; + } }; public isUploading = (clientId: string) => { diff --git a/app/utils/file/file_picker/index.ts b/app/utils/file/file_picker/index.ts index 700acc589..692dbef1b 100644 --- a/app/utils/file/file_picker/index.ts +++ b/app/utils/file/file_picker/index.ts @@ -11,6 +11,7 @@ import Permissions from 'react-native-permissions'; import {dismissBottomSheet} from '@screens/navigation'; import {extractFileInfo, lookupMimeType} from '@utils/file'; +import {logError} from '@utils/log'; const MattermostManaged = NativeModules.MattermostManaged; @@ -116,6 +117,7 @@ export default class FilePickerUtil { private getFilesFromResponse = async (response: ImagePickerResponse): Promise => { if (!response?.assets?.length) { + logError('no assets in response'); return []; } @@ -129,12 +131,14 @@ export default class FilePickerUtil { const uri = (await MattermostManaged.getFilePath(file.uri)).filePath; const type = file.type || lookupMimeType(uri); let fileName = file.fileName; - if (type.includes('video/')) { - fileName = uri.split('\\').pop().split('/').pop(); + if (type.includes('video/') && uri) { + fileName = decodeURIComponent(uri.split('\\').pop().split('/').pop()); } if (uri) { files.push({...file, fileName, uri, type, width: file.width, height: file.height}); + } else { + logError('attaching file reponse return empty uri'); } } }))); @@ -229,10 +233,10 @@ export default class FilePickerUtil { if (uri === undefined) { return {doc: undefined}; } + + doc.uri = uri; } - // Decode file uri to get the actual path - doc.uri = decodeURIComponent(uri); return {doc}; }; @@ -298,6 +302,7 @@ export default class FilePickerUtil { launchImageLibrary(options, async (response: ImagePickerResponse) => { StatusBar.setHidden(false); if (response.errorMessage || response.didCancel) { + logError('Attach failed', response.errorMessage); return; } diff --git a/app/utils/file/index.ts b/app/utils/file/index.ts index 17d36ac9f..b8d633d5e 100644 --- a/app/utils/file/index.ts +++ b/app/utils/file/index.ts @@ -16,6 +16,7 @@ import Permissions, {PERMISSIONS} from 'react-native-permissions'; import {Files} from '@constants'; import {generateId} from '@utils/general'; import keyMirror from '@utils/key_mirror'; +import {logError} from '@utils/log'; import {deleteEntititesFile, getIOSAppGroupDetails} from '@utils/mattermost_managed'; import {hashCode} from '@utils/security'; @@ -374,7 +375,8 @@ export async function extractFileInfo(files: Array { - if (!file) { + if (!file || !file.uri) { + logError('extractFileInfo no file or url'); return; } @@ -389,16 +391,16 @@ export async function extractFileInfo(files: Array