react-native-file-access
react-native-file-access copied to clipboard
stat and deleteFile say file does not exist for files in scoped storage in an SD card
react-native: 0.66.1 react-native-file-access: 2.4.4 Platform: Android 11
Bug I can't seem to delete files from scoped storage on an external SD card.
I'm trying to delete a file in scoped storage with:
await FileSystem.unlink('content://com.android.externalstorage.documents/tree/01F6-AC3F%3APodverse/document/01F6-AC3F%3APodverse/D9_Zc6_nz.mp3')
But I get the error message:
Error: 'content://com.android.externalstorage.documents/tree/01F6-AC3F%3APodverse/document/01F6-AC3F%3APodverse/D9_Zc6_nz.mp3' does not exist.
I get the same error message when I call:
await FileSystem.stat('content://com.android.externalstorage.documents/tree/01F6-AC3F%3APodverse/document/01F6-AC3F%3APodverse/D9_Zc6_nz.mp3')
@alpha0010 just fixed a different issue with calling await FileSystem.cp(...) with SD card scoped storage. Could there be corresponding fixes needed for stat and deleteFile?
I have also tried deleting these files with react-native-fs and react-native-scoped-storage. react-native-fs failed to delete the file because of an access issue. react-native-scoped-storage has a different bug where it deletes the whole directory instead of the file specified 🤦♂️
Yes, looks like the same problem as #52 hits these other APIs as well.
Can you try react-native-file-access@beta? One key difference is if you are using a scoped storage uri, you must use AndroidScoped.appendPath(dir, 'data.txt') instead of dir + '/data.txt' when generating paths.
It's working! 🥳 thanks so much for the quick fix!
https://github.com/podverse/podverse-rn/pull/1123/commits/73d3d89479c1c41cf1f4f3ebb208148be18d8e21#diff-b4ecc4e9e3fb1d360df3bc0ae6939c7471d36bc423571f28de6b0744a8c02d9eR245-R246