Skip to content

Commit 5f6f4bc

Browse files
committed
chore: retry when file saving failure on android
1 parent 364f805 commit 5f6f4bc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/uikit-react-native/src/platform/createFileService.native.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type * as Permissions from 'react-native-permissions';
77
import type { Permission } from 'react-native-permissions';
88

99
import {
10+
Logger,
1011
getFileExtension,
1112
getFileExtensionFromMime,
1213
getFileExtensionFromUri,
@@ -206,7 +207,10 @@ const createNativeFileService = ({
206207
if (Platform.OS === 'android') {
207208
const externalDirMap = { 'file': 'downloads', 'audio': 'audio', 'image': 'images', 'video': 'video' } as const;
208209
const externalDir = externalDirMap[file.type];
209-
await fsModule.FileSystem.cpExternal(downloadedPath, file.name, externalDir);
210+
await fsModule.FileSystem.cpExternal(downloadedPath, file.name, externalDir).catch(() => {
211+
Logger.error('Failed to save file to external storage. Retry saving to downloads directory instead.');
212+
return fsModule.FileSystem.cpExternal(downloadedPath, file.name, 'downloads');
213+
});
210214
}
211215

212216
return downloadedPath;

0 commit comments

Comments
 (0)