Irf*_*mad 5 android react-native react-native-android react-native-fs
我正在尝试使用以下代码将文件复制到另一个外部文件夹的简单代码:
RNFS.copyFile(sourcePath, destinationPath)
.then(result => {
console.log('file copied:', result);
})
.catch(err => {
console.log('error: ', err.message, err.code);
});
Run Code Online (Sandbox Code Playgroud)
我已经授予Android.Permission在外部目录中进行读写的权限,但它仍然返回此错误:
error: EISDIR: illegal operation on a directory, read '/storage/emulated/0/' EISDIR
Run Code Online (Sandbox Code Playgroud)
这是依赖项:
"react": "16.9.0",
"react-native": "0.61.2",
"react-native-fs": "^2.15.2"
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我请求正确的许可吗?
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
Run Code Online (Sandbox Code Playgroud)
提前感谢您的帮助
我已经解决了这个问题,这是一个愚蠢的错误。我忘记在目标路径 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);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7994 次 |
| 最近记录: |