RN 从 IOS 中的 URL 获取 blob 下载 docx 或 pdf [英] RN fetch blob download docx or pdf from URL in IOS
问题描述
做了什么:
在 Android 中实现,并在 android 中的特定 DCIM 目录
中下载.在 ios 中使用 DocumentDir
下载 pdf 或 docx 文件.使用 "rn-fetch-blob": "^0.12.0"
;
Implemented in Android and its getting downloaded in specific DCIM directory
in android.
In ios using DocumentDir
to download the pdf or docx file. Using "rn-fetch-blob": "^0.12.0"
;
错误:
在 IOS 中,它在控制台中显示消息:
In IOS it says the message in console :
文件保存到/var/mobile/Containers/Data/Application/E6FDC2DD-7FCA-44DC-85C4-A275078F8825/Documents/wow13.pdf
The file saved to /var/mobile/Containers/Data/Application/E6FDC2DD-7FCA-44DC-85C4-A275078F8825/Documents/wow13.pdf
要下载的代码是这样的:
The code to download is something like this :
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 中缺少任何权限吗?尚未为 IOS 添加任何权限.
But i cannot get where the file is downloaded in my iphone 7 real device. Is there any permission i'm missing in IOS? Havent added any permission for IOS.
推荐答案
感谢 pruthvi,我得到了答案,对于 ios 我需要提示用户:
Thanks to pruthvi, i got the answer , for ios i need to prompt the user:
.then(resp => {
// console.log(resp);
if (Platform.OS === "ios") {
RNFetchBlob.ios.openDocument(resp.data);
}
})
希望对大家有帮助
这篇关于RN 从 IOS 中的 URL 获取 blob 下载 docx 或 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!