【发布时间】:2020-02-04 06:51:20
【问题描述】:
做了什么:
在 Android 中实现,并在 Android 中的特定 DCIM directory 中下载。
在 ios 中使用DocumentDir 下载 pdf 或 docx 文件。使用"rn-fetch-blob": "^0.12.0";
错误:
在 IOS 中,它在控制台中显示消息:
文件保存到 /var/mobile/Containers/Data/Application/E6FDC2DD-7FCA-44DC-85C4-A275078F8825/Documents/wow13.pdf
要下载的代码是这样的:
downloadFileOnSuccess = async () => {
let dirs =
Platform.OS == 'ios'
? RNFetchBlob.fs.dirs.DocumentDir
: RNFetchBlob.fs.dirs.DCIMDir;
console.log(dirs, 'document path');
RNFetchBlob.config({
// response data will be saved to this path if it has access right.
fileCache: true,
path: dirs + `/wow13.pdf`,
})
.fetch(
'GET',
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
{
//some headers ..
},
)
.then(res => {
// the path should be dirs.DocumentDir + 'path-to-file.anything'
console.log('The file saved to ', res.path());
});
};
但我无法在我的 iphone 7 真实设备中找到文件的下载位置。我在IOS中缺少任何权限吗? Havent为IOS添加了任何权限。
【问题讨论】:
-
嘿,使用 LibraryDirectoryPath,而不是 DocumentDir 路径。
-
即使有库路径我也看不到任何这样的文件
-
是的,但首先您需要创建自定义文件夹。变量 PATH_TO_CREATE =
${RNFS.LibraryDirectoryPath}/Your_Folder_Name; RNFetchBlob.fs.mkdir(PATH_TO_CREATE) .then(() => { ... }) .catch((err) => { ... }); -
在 RNFS 中有很多选项可以将您的文件保存在 ios 和 android...bcoz 我已经完成了 rnfs ..
-
不。 RNFS.mkdir(PATH_TO_CREATE).then((result)=>{ console.log('Folder Created'); }).catch((err) => { console.log('err', err) });
标签: ios react-native rn-fetch-blob