How to save the file to device's folder like download

Yes, I have the same problem

1 Like

do we have any solution for this? if I plug in usb cable to my laptop and on phone popup, select allow for phone storage access, this will enable write access from my app. However without cable, just open my standalone app, the app can’t write any thing to ${FileSystem.documentDirectory}SQLite

Why is it very difficult to save file on expo?
No solution?
No progress for expo team?
No sample both android and ios?
No package?

Not sure if this is what you guys are looking for as the questiono was pretty ambiguous but here’s a gist of my implementation for image caching using FileSystem.downloadAsync and redux.

It gives me Permission denied how to resolve this? am developing for Android @mossypig

I think you probably have to use the Camera permission. I already have that permission for a totally different part of my app that was done before I ever tried this. Try requesting and accepting permission to the camera to save / edit files. @answary_a

Thanks, it worked. @mossypig

MediaLibrary.createAssetAsync() is working for only these format =>
“audio”: “audio”,
“photo”: “photo”,
“video”: “video”,
If you have this format then you can access gallery folder and save it, but if file format is .pdf or xlsx or csv then you can’t,

other solution is you have to open Linking.openURL() , then and download the file which is available in downloaded folder,

this is not proper solution. expo team have to look into this problem to access these type of file

2 Likes

This is a very serious disadvantage of expo. There is no way to access public storage apart from camera roll. I don’t want to start saving pdf and word documents into people’s galleries.

I suggest you upvote this feature request:

https://expo.canny.io/feature-requests/p/expose-native-filesystems

This one might also be relevant:

https://expo.canny.io/feature-requests/p/add-externaldirectory-to-expofilesystem

Thanks. Upvoted both. Hope this feature get’s added soon.

I ejected my app in the meantime as I cannot proceed with expo as is :expressionless:

Does expo use a bounty system? I would gladly put up some money to get this feature rolled in.

1 Like

Not as far as I know, but maybe contact secure@expo.io and see what they say.

Otherwise maybe you can implement it yourself and contribute it back to the project (or pay someone else to do it), but it would be best to co-ordinate with the Expo team.

Same to me

can u show me how to get the .db file please …?
i try many things to do it but dont understand why its doesnt work for me .
this is my code :

saveDbData = async () => {
    const { data, isLoaded } = this.state;
    for (let i = 0; i < data.length; i++) {
      const mediaData = data[i];
      const dbResult = await insertPlace(
        mediaData.artist,
        mediaData.image,
        mediaData.title,
        mediaData.url
      );
      const { uri } = await FileSystem.getInfoAsync(
        `${FileSystem.documentDirectory}SQLite/${'places.db'}`
    )
     console.log("THIS IS PATH OF THE DB",uri)// WHEN U WANT SEE THE PATH OF THE DB FILE 

    }
     
    const fetchawesome = await fetchPlaces();
     console.log("THIS MY DB :",fetchawesome) //WHEN U WANT PRINT THE CONTENT OF THE DB
    
  };

why dont you just open the file link trough react native webview, then the file will be downloaded to your device,

how can I do that. I am connecting to a site with Webview. I need to download pdf from the site I’m connected to. Normally when I go to the site with the browser, it downloads. But I can’t download from the app

You can use MediaLibrary, after download.

... 
const downloaded = await FileSystem.downloadAsync(file_uri, new_path, { md5: true });
saveFileAsync(downloaded.uri);
...
export async function saveFileAsync(file_uri) {
  try {
    // const { status, permissions } = await MediaLibrary.requestPermissionsAsync();
    const { status, permissions } = await Permissions.askAsync(Permissions.MEDIA_LIBRARY);
    if (status === "granted" && permissions.mediaLibrary.accessPrivileges !== 'limited') {
      const asset = await MediaLibrary.createAssetAsync(file_uri);
      const album = await MediaLibrary.getAlbumAsync('Download');
      if (album === null) {
        await MediaLibrary.createAlbumAsync('Download', asset, false);
      } else {
        await MediaLibrary.addAssetsToAlbumAsync([asset], 'Download', false);
      }
      return true;
    }
    return false;
  } catch (error) {
    console.log('ERR: saveFileAsync', error);
    throw error;
  }
}

It’s works in IOS?

For now yes. Have you tested?

Aqui eu testei e funcionou normal…