Closed ghost closed 4 years ago
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.
If you're using expo, you can use its four libraries for downloading and sharing files
- expo-sharing
- expo-media-library
- expo-permissions
- expo-file-system
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.
This doesn't work anymore in expo SDK 41 or 42, Does somebody knows the new way to download a file from app?
How to get width and height of image from file:// in expo?
If you're using expo, you can use its four libraries for downloading and sharing files
- expo-sharing
- expo-media-library
- expo-permissions
- expo-file-system
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.
This doesn't work anymore in expo SDK 41 or 42, Does somebody knows the new way to download a file from app?
https://github.com/thareekanvar/expo-downloads-manager try this
If you're using expo, you can use its four libraries for downloading and sharing files
- expo-sharing
- expo-media-library
- expo-permissions
- expo-file-system
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.
I'm facing some issue while downloading pdf
const url = "<link>";
const downloadPath = FileSystem.documentDirectory + `sample.pdf`;
const { uri } = await FileSystem.downloadAsync(url, downloadPath);
const asset = await MediaLibrary.createAssetAsync(uri); // the code breaks here
Here is the error message i'm getting as an warning and file fails to download at that line
Possible Unhandled Promise Rejection (id: 13):
Error: Could not create asset
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.