问题描述
我正在尝试使用 react-native-fs/rn-fetch-blob 在外部/可移动 SD 卡中创建一个文件... 但是我的权限被拒绝了......我什至要求读取和写入外部存储的运行时权限...... 根据我遇到的情况,我猜运行时权限是指共享存储,即内部存储... 那么,我应该请求什么样的权限,或者是否有解决方法来创建文件?
const getExtSdpath = async () => {
let path = '';
await RNFS.getAllExternalFilesDirs()
.then((res) => {
console.log(res[1]);
const pathArray = res[1].split('/');
path = '/' + pathArray[1] + '/' + pathArray[2];
})
.catch((err) => {
console.log(err);
});
return path;
};
const check = async () => {
const extSdpath = await getExtSdpath(); //This gives : /storage/38B1-141B
var path = extSdpath + '/test.txt'; //This gives : /storage/38B1-141B/test.txt
// write the file
RNFS.writeFile(path,'Lorem ipsum dolor sit amet','utf8')
.then((success) => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log(err.message); // This gives : ENOENT: Permission denied,open '/storage/38B1-141B/test.txt'
});
};
useEffect(() => {
check();
},[]);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)