Android: "Permission denied" – no matter what I do
See original GitHub issueHi, I am trying to save some base64 data to file, but somehow I can’t get it to work. Everytime I am trying to access external storage (/storage/emulated/0
), I get Permission denied
from createFile()
or writeFile()
—I have tried both already. I am also asking for permission beforehand, as you can see in my code snippet. I also added the stuff to AndroidManifest.xml
.
The only location that doesn’t raise the Permission denied
exception is RNFetchBlob.fs.dirs.DocumentDir
, but that is /data/user/0/{bundleId}/files
and I am not sure, what that’s translating to. This exact path does not exist on my phone, but I suspect it’s {Internal storage}/Android/data/{bundleId}/files
. Even so, after running createFile()
/writeFile()
“successfully” there’s no file at that location.
Am I missing something crucial here? I’m really out of my depth on this one. I hope someone can help me.
-
the version of installed library and RN project. react-native: v0.63.3 rn-fetch-blob: v0.12.0 Android 10 (Samsung Galaxy S10; One UI v2.5)
-
a sample code snippet/repository is very helpful to spotting the problem.
const permissions = await Permissions.requestMultiple([
Permissions.PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE,
Permissions.PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE,
]);
console.log("permissions:", permissions);
if (
permissions[Permissions.PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE] ===
Permissions.RESULTS.GRANTED &&
permissions[Permissions.PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE] ===
Permissions.RESULTS.GRANTED
) {
try {
// const createdFilePath = await RNFetchBlob.fs.createFile(path, base64Data, 'base64');
const createdFilePath = await RNFetchBlob.fs.createFile(
`${RNFetchBlob.fs.dirs.DownloadDir}/test.txt`,
"Hello World",
"utf8"
);
if (createdFilePath) {
console.log("created file path:", createdFilePath);
return true;
}
console.warn("saveToFile() :: File was not successfully saved to dir.");
return false;
} catch (e) {
console.warn(
"saveToFile() :: RNFetchBlob.fs.createFile raised an exception:",
e.message
);
return false;
}
} else {
console.warn("Permission to write to external storage not granted.");
}
If you need any additional info, just let me know.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:23
Top GitHub Comments
I got similar issue, I tried to write a file to
RNFetchBlob.fs.dirs.DownloadDir
but it always returnsPermisson Denied
. After digging a bit more into it turns out Android 10 introduce a new storage paradigm called scoped storage. So far the only workaround that I found is to addto your
AndroidManifest.xml
but this is only temporary. It would be amazing ifrn-fetch-blob
could support scoped storage 🙇 .Google won’t allow
android:requestLegacyExternalStorage
after May 5. This needs to be solved soon