我正在使用react-native-fs进行文件系统访问。然而,我无法访问ios中的文件。
代码如下:
RNFS.readDir(RNFS.MainBundlePath)
.then((result) => {
console.log('Got result', result);
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then((statResult) => {
console.log('stat result',statResult);
if(statResult[0].isFile()){
return RNFS.readFile(statResult[1], 'utf8');
}
return 'no file';
})
.then((contents) => {
console.log('Got Contents',contents);
})
.catch((err) => {
console.log(err.message, err.code);
})我正在获取MainBundlePath的路径文件,但没有获取本地存储的任何其他文件/文件夹。
发布于 2017-11-19 22:16:15
回答我自己的问题。我终于可以使用react- native -fs库访问存储在android上的所有文件了。
已尝试使用给定常量列表中的ExternalStorageDirectoryPath。
下面是代码(由react-native-fs git repo提供):
RNFS.readDir(RNFS.ExternalStorageDirectoryPath)
.then((result) => {
console.log('GOT RESULT', result);
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then((statResult) => {
if (statResult[0].isFile()) {
return RNFS.readFile(statResult[1], 'utf8');
}
return 'no file';
})
.then((contents) => {
console.log(contents);
})
.catch((err) => {
console.log(err.message, err.code);
});发布于 2017-11-09 16:47:27
我也有同样的问题。我认为您必须使用"RNFS.DocumentDirectoryPath",因为您没有对MainBundle的完全访问权限。
https://stackoverflow.com/questions/47197227
复制相似问题