如何解决ENOENT:权限被拒绝,打开“/storage/38B1-141B/test.txt”尝试使用 react-native-fs
我正在尝试使用 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 举报,一经查实,本站将立刻删除。