alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
307 stars 19 forks source link

written file does not show up and many files not shown with FileSystem.ls #24

Closed FrederickEngelhardt closed 3 years ago

FrederickEngelhardt commented 3 years ago

Written files that I write to download are not showing up.

File extensions missing are[apk, txt,bak,pdf,docx]

Are there file extensions that are ignored? Is there a permission I am missing?

Example

const downloadPath =`${Dirs.SDCardDir}/Download`
const output = await FileSystem.ls(`${Dirs.SDCardDir}/Download`)
alpha0010 commented 3 years ago

Nothing should be ignored. Do you have READ_EXTERNAL_STORAGE and/or WRITE_EXTERNAL_STORAGE granted https://reactnative.dev/docs/permissionsandroid ? Are there any error messages?

alpha0010 commented 3 years ago

Note that file access has become a lot more restrictive on recent API levels https://developer.android.com/training/data-storage; using Dirs.SDCardDir is likely to fail on API 29+.

I have not implemented all features of MediaStore and Storage Access Framework. If your use case is not possible with this library (but is compatible with Android's new permissions model), let me know and I will see what I can do.

FrederickEngelhardt commented 3 years ago

I ended up resolving this issue by adding the following to the android/app/src/main/AndroidManifest.xml

    <application
      android:requestLegacyExternalStorage="true"

Is this considered a resolution? Or will legacyExternalStorage eventually not exist?

Edit: Looks like this is a better solution

android-docs

    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

The above permission does not require android:requestLegacyExternalStorage="true". My use case is a filesystem manager so this permission makes sense.