[Gekidou] Fix video uploads (#6440)

This commit is contained in:
Elias Nahum 2022-06-30 19:16:37 -04:00 committed by GitHub
parent 306fbba3a7
commit d09ead850e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 14 deletions

View file

@ -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);
}
}

View file

@ -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,

View file

@ -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) => {

View file

@ -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;
}

View file

@ -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;
}
}