android - EISDIR:对目录的非法操作,在 React Native 文件系统中读取
问题描述
我正在尝试使用以下代码将文件复制到另一个外部文件夹的简单代码:
RNFS.copyFile(sourcePath, destinationPath)
.then(result => {
console.log('file copied:', result);
})
.catch(err => {
console.log('error: ', err.message, err.code);
});
而且我已经授予Android.Permission
在外部目录中的读写权限,但它仍然返回此错误:
error: EISDIR: illegal operation on a directory, read '/storage/emulated/0/' EISDIR
这是依赖项:
"react": "16.9.0",
"react-native": "0.61.2",
"react-native-fs": "^2.15.2"
顺便说一句,我请求正确的许可吗?
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
提前感谢您的帮助
解决方案
我已经解决了这个问题,这是一个愚蠢的错误。我忘了在目标路径 url 中提及文件的名称:
let sourcePath = "/storage/emulated/0/SourceFolder";
let destinationPath = "/storage/emulated/0/DestinationFolder";
let FileName = 'abc.jpg';
destinationPath = destinationPath +"/"+ FileName;
RNFS.copyFile(sourcePath, destinationPath)
.then(result => {
console.log('file copied:', result);
})
.catch(err => {
console.log(err);
});
推荐阅读
- xml - 使用正则表达式验证 xsd 字符串
- angular - Angular:从不同的 REST 端点获取数据
- html - 表格标题中的单元格间距
- sql - 我怎样才能把这个类图变成一个数据模型?
- html - 如何在 BeautifulSoup 中从 YahooFinance 下载链接?
- python - 使用 unittest 构建 Python 项目
- azure - 如何从另一个模块调用物联网边缘代理的直接方法?
- java - 如何从 themoviedb api 获取图像
- java - 如何在 Spring Boot 中配置缓存,使其不缓存错误代码 500/401/403 等错误
- python - 如何使用 selenium 和 python 获取表数据