react-native-fs
react-native-fs copied to clipboard
Getting EACCES (Permission denied) for manually added files for android version 11 and above. sdk version 30 and above
Hi i am able to access files external directory files using following path.
RNFS.ExternalStorageDirectoryPath + '/Documents/myFolder'
I am able to create folder and files in this path and also able to read them.
But if i try to add a file manually into the same path and then the read fails with the error "EACCES (Permission denied)".
I checked the permission of both the files, and both manually and programatically created files have same access. I am stuck here to resolve this issue like forever now. what could be the issue with manually added files ?
const folderPath=RNFS.ExternalStorageDirectoryPath + '/Documents/myFolder';
var fileSearchString = '/test.txt';
var finalFileToSearch = folderPath + fileSearchString;
RNFS.readDir(folderPath)
.then(result => {
console.log('GOT RESULT', result);
// stat the first file
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then(statResult => {
if (statResult[0].isFile()) {
// if we have a file, read it
return RNFS.readFile(finalFileToSearch, 'utf8');
}
return 'no file';
})
.then(contents => {
// log the file contents
console.log('File Contents : ', contents);
})
.catch(err => {
console.log('ERROR >>>> ', err.message, err.code);
});
This above is happening only for android SDK api >29 / android 11 and above. I am able to access files for android 10 and below.
same for me
+1