【发布时间】:2019-03-13 16:20:18
【问题描述】:
我正在使用 react-native-fs 从服务器下载文件并保存。下载它们后,我将使用 react-native-file-viewer 打开它们。这个过程完全正常:我可以在查看器中下载并打开它,但我无法从查看器中将文件保存在文件应用程序中,尽管我可以保存在 iCloud 中但不能保存在 iPhone 中。 下载的文件存放在类似
的地方/var/mobile/Containers/Data/Application/CCF6CD16-A62A-48BB-92F3-3021195CFE0C/Documents/react-native-pdf.pdf
但这不会显示在“文件”应用中。
我用来下载和查看文件的代码如下
RNFS.downloadFile({
fromUrl: 'http://www.mywebsite.com/react-native-pdfurl.pdf',
toFile: `${RNFS.DocumentDirectoryPath}/react-native-pdfurl.pdf`,
}).promise.then((r) => {
console.log('yo yo yo ');
this.setState({ isDone: true });
const path = `${RNFS.DocumentDirectoryPath}/react-native-pdfurl.pdf`;
FileViewer.open(path)
.then(() => {
// success
})
.catch(error => {
// error
});
RNFS.readDir(RNFS.DocumentDirectoryPath).then(files => {
console.log(files);
})
.catch(err => {
console.log(err.message, err.code);
});
});
readDir 让我得到保存文件的名称路径。但这不会反映在 File 应用程序的任何文件夹中。 我的问题是如何以文件应用程序中显示的方式保存文件。
【问题讨论】:
-
你得到答案了吗?
-
检查我的答案以访问 ios 和 android 目录
标签: ios iphone react-native react-native-fs