react-native-fs
react-native-fs copied to clipboard
ENOENT: open failed: EACCES (Permission denied)
I'm getting this error whilst trying to open files in the directory ExternalDirectoryPath
.
I have seen that others have fixed it by targeting a lower SDK version (29 max) so that they can opt out of scoped storage.
This isn't working for me consistently and after reading the android docs it seems this shouldn't be causing any issue, we shouldn't even need to request permissions.
For reference ExternalDirectoryPath
in RNFS returns the same as androids getExternalFilesDir()
method which is meant to not require permissions in most cases.
Anyone experienced this?
@Sid-Turner-Ellis have you found a solution? I am experiencing the same issue
@dmsierra11 I'm going to be looking into this shortly, I'm probably going to switch to a different module that is better contained.
Let me know if you find a solution
@Sid-Turner-Ellis Are you getting this error for files you added manually or files which you create from the application?
I using the following path : RNFS.ExternalStorageDirectoryPath + '/Documents/anyfoldername'
I am able to access files inside a folder which are created from application but if i add a file manually in the same folder then i am not able to access it. Getting "EACCES (Permission denied)" this error for manually created files.
@Sid-Turner-Ellis You rightly said we dont need permission also to read for 30+ SDK version. Were you able to resolve this with some other library ?
@pruthvirajkarurcodewave When you say "add manually" do you mean adding from within the application or via ADB?
I was getting the error when trying to access files that I created within the app, I ended up moving to use the FS module in this library - https://github.com/RonRadtke/react-native-blob-util
Though heads up that I haven't tested this yet
@Sid-Turner-Ellis added manually means, any files apart from the once created from my application are not accessible. images, and media files are accessible but not .txt,.data,.csv etc are not accessible for the app. where as i am able to access files in android version 10 and below.
I just checked, I'm still getting the issue with the new library so I guess I'm going to have to look into it again, same as what you are describing though - manually added files are not working for me and I am unable to delete them from the app
On Thu, 27 Apr 2023, 9:47 am pruthvirajkarurcodewave, < @.***> wrote:
added manually means, any files apart from the once created from my application are not accessible. images, and media files are accessible but not .txt,.data,.csv etc are not accessible for the app. where as i am able to access files in android version 10 and below.
— Reply to this email directly, view it on GitHub https://github.com/itinance/react-native-fs/issues/1175#issuecomment-1524527815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOWLSCZF2BANGBYIDXIOW43XDHM5XANCNFSM6AAAAAAVXTQ3MU . You are receiving this because you were mentioned.Message ID: @.***>
You can try with this piece in the manifest.xml
and request the permission so:
@JARG85 Gallary and other media files will still be accessible. But post android SDK 29 i am not able to read files which are not created from the application. where as other media files are visible to the application. Files have been removed from the permission from android API level 30
@pruthvirajkarurcodewave ohh that's right, the reason is that google implemented a new way for storing the applications, you can try to use a URI to point to the files but I think it's tedious, try using: react-native-document-picker. and look this: https://developer.android.com/training/data-storage
To confirm moving to this library fixed any storage issues. It's also more actively maintained than this
@JARG85 In my case the user would not know the file name to search. if yes i would have chosen react-native-document-picker. In my use case, User reads some data from the QR code or NFC using that data i have to search a file from the external storage where user himself would have already placed files manually in external folder.
@Sid-Turner-Ellis does the new library you are referring able to read manually added files ?
What do you mean when files are added manually?
When I originally said that I was referring to cases where you push files into the android emulators storage with ADB for testing purposes and I stopped doing that so I'm not sure.
Try it out though, I haven't had any issues with it so far
On Fri, 12 May 2023, 9:52 am pruthvirajkarurcodewave, < @.***> wrote:
@JARG85 https://github.com/JARG85 In my case the user would not know the file name to search. if yes i would have chosen react-native-document-picker. In my use case, User reads some data from the QR code or NFC using that data i have to search a file from the external storage where user himself would have already placed files manually in external folder. @Sid-Turner-Ellis https://github.com/Sid-Turner-Ellis does the new library you are referring able to read manually added files ?
— Reply to this email directly, view it on GitHub https://github.com/itinance/react-native-fs/issues/1175#issuecomment-1544990608, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOWLSC6USF6OPR5UYI26TS3XFWJVZANCNFSM6AAAAAAVXTQ3MU . You are receiving this because you were mentioned.Message ID: @.***>
@Sid-Turner-Ellis My use case is The app creates a folder say "MyFolder" then app creates a file using "RNFS.writeFile"
method. Since the file was created from the app itself app can read it.
In the second case if the app downloads a file into the same folder path "MyFolder"
, the app can still read that file.
In the last case if the user copy pastes a new file into "MyFolder"
folder, then app cannot access it. This is what i am calling as manually added files. Even this is possible for android version 10 and below. In Android version 11 and above we cannot read files where the owner is not the app. in the above first 2 use cases the owenr of the files would be app so it can access it. In the current case since file was manually added to the folder the app is not the ownner of it which is why i am getting this error : "EACCES (Permission denied)"
Is there any way we can read/access such files where app is not the owner in android version 11 and above.
Folder is created in this path RNFS.ExternalStorageDirectoryPath + '/Documents'+'/MyFolder'
Hello. Do you guys have any solution to resolve this problem?
any solution???