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

I have same problem

Funciona para archivos con extensión diferente al tipo image/*?? es que lo intento con .pdf pero expo me niega el acceso a escritura y lectura para ese tipo

Please send the console.log to ‘permissions’ and check for the permission for IOS/Android in expo app.json configuration.

Hello everyone!
I am trying to make a database backup so that the user can save the data and load it later into the same application (on any device). At first I wanted the user to be able to choose where he want to save the file with “StorageAccessFramework.requestDirectoryPermissionsAsync()”. Now I’m trying to do it anywhere. But at the moment of calling “createAssetAsync” the “Expo go” crashes regularly, and I don’t undestand why.

export async function backupDatabase() {
try {
     const res  = await MediaLibrary.requestPermissionsAsync();
     const database = `${FileSystem.documentDirectory}SQLite/db.db`;
     if (res.granted) {
          let backup = await MediaLibrary.createAssetAsync(database); //breaks down in this place 
          const folder = await MediaLibrary.getAlbumAsync('Test');
          if (folder) {
              await MediaLibrary.addAssetsToAlbumAsync([backup], folder, false);
          } else {
              await MediaLibrary.createAlbumAsync('Test', backup, false);
          }
     } 
}

And I can’t to check this solution: How to save the file to device's folder like download - #19 by mossypig. Somebody could help me to resolve this problem?

1 Like

Have you found the sollution to this problem? Currently i’m facing the same issue and it’s probably due to createAssetAsync, which does not allow to work with db files

1 Like

CameraRoll is now depreciated. Any other solution to download .xlsx file into android OS? I’m able to Download .xlsx file but I got 2 issues to it.

  • I want to save in ‘Download’ folder but it saving in ‘DCIM’ folder.
  • App automatically exits once it saves that file in ‘DCIM’ folder.

So any body has any solution for this? And why expo team is not finding any solution for this? This problem is rose since more than a year.

1 Like

on android 11 yes

Are you facing the same issue?

here

One temp solution is to use the Sharing API to allow users to select the save location. Sample like:

import * as Sharing from 'expo-sharing';
import * as FileSystem from 'expo-file-system';

// Download the file and get its local URI
const { uri } = await FileSystem.downloadAsync(
  'https://example.com/file.pdf',
  FileSystem.cacheDirectory + 'file.pdf'
);

// Share the file with the user
await Sharing.shareAsync(uri);
1 Like

@smarkm but this would still save it in the apps directory since you are using FileSyastem.cacheDirectory