forked from Ivasoft/mattermost-mobile
[Gekidou] Fix video uploads (#6440)
This commit is contained in:
@@ -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<Asset[]> => {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Asset | DocumentPickerRespons
|
||||
const out: ExtractedFileInfo[] = [];
|
||||
|
||||
await Promise.all(files.map(async (file) => {
|
||||
if (!file) {
|
||||
if (!file || !file.uri) {
|
||||
logError('extractFileInfo no file or url');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -389,16 +391,16 @@ export async function extractFileInfo(files: Array<Asset | DocumentPickerRespons
|
||||
outFile.size = file.fileSize || 0;
|
||||
outFile.name = file.fileName || '';
|
||||
} else {
|
||||
const path = Platform.select({
|
||||
const localPath = Platform.select({
|
||||
ios: (file.uri || '').replace('file://', ''),
|
||||
default: file.uri || '',
|
||||
});
|
||||
let fileInfo;
|
||||
try {
|
||||
fileInfo = await FileSystem.stat(path);
|
||||
const fileInfo = await FileSystem.stat(decodeURIComponent(localPath));
|
||||
outFile.size = fileInfo.size || 0;
|
||||
outFile.name = path.substring(path.lastIndexOf('/') + 1);
|
||||
outFile.name = localPath.substring(localPath.lastIndexOf('/') + 1);
|
||||
} catch (e) {
|
||||
logError('extractFileInfo', e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user