alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
298 stars 18 forks source link

How to list all files in the download or document Dir #57

Closed lewatt23 closed 1 year ago

lewatt23 commented 1 year ago

Hello thanks for the lib, i am having a couple to worries regarding the implementation of the API's. My first worry is where the Dirs.DocumentDir actually saves the files, cause am saving my files there but when i try to read i can't find them (when i open my filemanger i can't find them). My second worry was how to read the content of the download, Aussiming i download a file and i used FileSystem.cpExternal to copy it to the download folder, is it possible to list the content of the download folder?. thanks sorry if it's too much ^^!

alpha0010 commented 1 year ago

For iOS, all files are within the app's sandbox. OS permissions make it impossible to write files elsewhere. However, UIFileSharingEnabled should make your app's files accessible from outside the app. Dirs.DocumentDir is selected via FileManager.SearchPathDirectory.documentDirectory, usually this is <app-sandbox-dir>/Documents.

For Android, the Dirs.* constants all point with the app's sandbox, except Dirs.SDCardDir. For unrestricted access to files outside the app's sandbox, the app requires permission MANAGE_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE (note that requesting these permissions generally flags app review, so the app needs justification why it requires such). FileSystem.cpExternal() submits a file to the Android OS, requesting it be placed in the referenced collection; the OS decides where specifically to put it. If you gain a resource uri (for example, by react-native-document-picker or react-native-scoped-storage - I hope to incorporate these types of features into RNFA at some point) you can use functions from this library, as if the uri were a normal path (so, get the downloads dir uri, then FileSystem.ls() on it). Accessing files/folders outside of the app's sandbox in this way does not require any special permissions. Dirs.DocumentDir is selected via [Context.getFilesDir()](https://developer.android.com/reference/android/content/Context#getFilesDir()), usually this is <app-sandbox-dir>/files.

If this does not meet your needs, feel free to open a feature request, with links to the Android/iOS documentation for the APIs you would like to access.

lewatt23 commented 1 year ago

Thanks for the respond :)