5

I am trying to do a data backup for my React Native App with expo go and expo-file-system

 await Filesystem.writeAsStringAsync(
   Filesystem.documentDirectory! + "GymTracker-Data.json",
   JSON.stringify(exportData)
 )

How do I access this documentDirectory with a file explorer app like File Manager or Amaze File Manager?

I tried printing out the path on the app but I can't find said path.

Ryan
  • 356
  • 1
  • 6
  • 26

3 Answers3

6

documentDirectory is your app's private internal directory, only accessible by your app. Third party apps like File Manager cannot access it.

At the moment, expo does not provide any API to write files to 'download' or other public directories. But this may change in future. Check these two posts discussing the issue.

https://forums.expo.dev/t/how-to-save-the-file-to-devices-folder-like-download/2398 https://expo.canny.io/feature-requests/p/ability-to-save-files-on-internal-storage

vinayr
  • 11,026
  • 3
  • 46
  • 42
2

you can use the expo-sharing library from expo together with the expo-file-system library.

With expo-file-system you download it to the internal private directory of your application.

and with expo-sharing you copy it to the iPhone files folder.

https://www.farhansayshi.com/post/how-to-save-files-to-a-device-folder-using-expo-and-react-native/

https://docs.expo.dev/versions/latest/sdk/sharing/#sharingoptions

enter image description here

drodriguez
  • 150
  • 2
  • 5
1

it worked for me by adding these two settings in the info.plist

<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

this will enable the application's public folder in the iPhone's file application

Reference: https://bignerdranch.com/blog/working-with-the-files-app-in-ios-11/

Note: this configuration will only work on IOS, not on Android.

drodriguez
  • 150
  • 2
  • 5