|
1 | 1 | import React, { PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react'; |
2 | | -import { KeyboardAvoidingViewProps, StyleSheet, Text, View } from 'react-native'; |
| 2 | +import { KeyboardAvoidingViewProps, Platform, StyleSheet, Text, View } from 'react-native'; |
3 | 3 |
|
4 | 4 | import debounce from 'lodash/debounce'; |
5 | 5 | import throttle from 'lodash/throttle'; |
@@ -74,7 +74,7 @@ import { |
74 | 74 | ThumbsUpReaction, |
75 | 75 | WutReaction, |
76 | 76 | } from '../../icons'; |
77 | | -import { FlatList as FlatListDefault, pickDocument } from '../../native'; |
| 77 | +import { FlatList as FlatListDefault, getLocalAssetUri, pickDocument } from '../../native'; |
78 | 78 | import * as dbApi from '../../store/apis'; |
79 | 79 | import type { DefaultStreamChatGenerics } from '../../types/types'; |
80 | 80 | import { addReactionToLocalState } from '../../utils/addReactionToLocalState'; |
@@ -1295,12 +1295,16 @@ const ChannelWithContext = < |
1295 | 1295 | attachment.image_url && |
1296 | 1296 | isLocalUrl(attachment.image_url) |
1297 | 1297 | ) { |
1298 | | - const filename = file.uri.replace(/^(file:\/\/|content:\/\/|assets-library:\/\/)/, ''); |
| 1298 | + // For the case of Expo CLI where you need to fetch the file uri from file id. Here it is only done for iOS since for android the file.uri is fine. |
| 1299 | + const localAssetURI = |
| 1300 | + Platform.OS === 'ios' && file.id && (await getLocalAssetUri(file.id)); |
| 1301 | + const uri = localAssetURI || file.uri || ''; |
| 1302 | + const filename = file.name ?? uri.replace(/^(file:\/\/|content:\/\/)/, ''); |
1299 | 1303 | const contentType = lookup(filename) || 'multipart/form-data'; |
1300 | 1304 |
|
1301 | 1305 | const uploadResponse = doImageUploadRequest |
1302 | 1306 | ? await doImageUploadRequest(file, channel) |
1303 | | - : await channel.sendImage(file?.uri, filename, contentType); |
| 1307 | + : await channel.sendImage(uri, filename, contentType); |
1304 | 1308 |
|
1305 | 1309 | attachment.image_url = uploadResponse.file; |
1306 | 1310 | delete attachment.originalFile; |
|
0 commit comments