const selectFile = async () => { try { if (Platform.OS === 'android') { const permission = await check(PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE); if (permission !== RESULTS.GRANTED) { const result = await request(PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE); if (result !== RESULTS.GRANTED) { throw new Error('Please allow the storage access permission request.'); } } } else if (Platform.OS === 'ios') { // TODO: } const result = await DocumentPicker.pick({ type: [ DocumentPicker.types.images, DocumentPicker.types.video, DocumentPicker.types.audio, DocumentPicker.types.plainText, DocumentPicker.types.zip ] }); const copyPath = `${RNFS.TemporaryDirectoryPath}/${result.name}`; await RNFS.copyFile(result.uri, copyPath); const fileStat = await RNFS.stat(copyPath); const params = new sendbird.FileMessageParams(); params.file = { ...result, uri: `file://${fileStat.path}` }; dispatch({ type: 'start-loading' }); channel.sendFileMessage(params, (err, message) => { dispatch({ type: 'end-loading' }); if (!err) { dispatch({ type: 'send-message', payload: { message } }); } else { setTimeout(() => { dispatch({ type: 'error', payload: { error: 'Failed to send a message.' } }); }, 500); } }); } catch (err) { console.log(err); if (!DocumentPicker.isCancel(err)) { dispatch({ type: 'error', payload: { error: err.message } }); } } };