-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathsaveFile.ts
More file actions
26 lines (23 loc) · 789 Bytes
/
saveFile.ts
File metadata and controls
26 lines (23 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let FileSystem;
try {
FileSystem = require('expo-file-system/legacy');
} catch (e) {
// do nothing
}
if (!FileSystem) {
console.log(
'expo-file-system is not installed. Installing this package will allow your users to save/delete file locally and access the cache dir for android/iOS.',
);
}
export const saveFile = FileSystem
? async ({ fileName, fromUrl }: { fileName: string; fromUrl: string }) => {
try {
const path = FileSystem.cacheDirectory + encodeURIComponent(fileName);
const downloadedImage = await FileSystem.downloadAsync(fromUrl, path);
return downloadedImage.uri;
} catch (error) {
console.log('Downloading image failed...', error);
throw new Error('Downloading image failed...');
}
}
: null;