Hi, i try to use rn-fetch-blob with Expo and there is an error occurs: "null is not an object (evaluating 'RNFetchBlob.DocumentDir')".
I saw a couple of comments that rn-fetch-blob doesn't support with expo. I didn't find any solution, also any information, if it should work with Expo. I try to find any solution to download files and open it.
Sorry if my question is duplicate and thanks for any help.
rn-fetch-blob implements native code, and so it cannot be used in expo based projects. You would need to eject from expo from my understanding
@Traviskn i am not on expo, but i am still getting this error on android
If you're using expo, you can use its four libraries for downloading and sharing files
async function downloadFile(url) {
// Downloading the file
let fileLocation = FileSystem.documentDirectory + "test.jpg";
FileSystem.downloadAsync(url, fileLocation)
.then(({url}) => {
// Saving the file in a folder name `MyImages`
const {status} = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === "granted") {
const asset = await MediaLibrary.createAssetAsync(url)
await MediaLibrary.createAlbumAsync("MyImages", asset, false)
}
// Sharing the downloded file
Sharing.shareAsync(fileLocation);
})
.catch(error => {
console.error(error);
})
}
It'll download the file and open the share modal for sharing.
Rn-fetch-blob is not supported for expo-projects and this is the only way I am able to find for now.
Maybe useful for some cases, not all.
Most helpful comment
If you're using expo, you can use its four libraries for downloading and sharing files
It'll download the file and open the share modal for sharing.
Rn-fetch-blob is not supported for expo-projects and this is the only way I am able to find for now.
Maybe useful for some cases, not all.