Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does rn-fetch-blob work with Expo? #517

Closed
ghost opened this issue Jan 11, 2020 · 8 comments
Closed

Does rn-fetch-blob work with Expo? #517

ghost opened this issue Jan 11, 2020 · 8 comments

Comments

@ghost
Copy link

ghost commented Jan 11, 2020

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.

@Traviskn
Copy link

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

@maneesha-krishna
Copy link

@Traviskn i am not on expo, but i am still getting this error on android

@actuallyakash
Copy link

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.

@praveen-jangir
Copy link

https://github.com/edugyangroup/Expo-blob

@earlwood
Copy link

earlwood commented Aug 2, 2021

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?

@VityaSchel
Copy link

How to get width and height of image from file:// in expo?

@thareekanvar
Copy link

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

@rahmanharoon
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants