我正在使用apisauce来处理基本的http请求,比如GET和POST,它工作得很好。现在我需要能够下载pdf文件了。有没有可能配上蜂酱?如果是这样的话,谁有一些示例代码?
发布于 2021-05-08 02:50:22
我对apisauce不太确定,但从互联网上的url下载pdf,
我更喜欢使用这个包:,因为它很稳定,并且有很好的文档。
请按照以下步骤操作:
在终端(MAC/Linux)或
纱线添加rn-fetch-blob
pod 'rn-fetch-blob',:路径模块‘../node_ => /rn-fetch-blob’
if (Platform.OS === 'android') ==>
RNFetchBlob.config({
fileCache: false,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
mime: 'application/pdf',
path:
`/storage/emulated/0/Download/${file_name}.pdf`,
},
})
.fetch('GET', api, {'Cache-Control': 'no-store'})
.then((res) => {})
.catch((errorMessage, statusCode) => {}); if (Platform.OS === 'ios')
const {
dirs: {DownloadDir, DocumentDir},
} = RNFetchBlob.fs;
const fPath = `${DocumentDir}/${file_name}.pdf`;
RNFetchBlob.config({
fileCache: true,
path: fPath,
notification: true,
appendExt: 'pdf',
})
.fetch('GET', api, {
Authorization: 'Token ' + token,
})
.then(async (resp) => {
RNFetchBlob.fs.writeFile(fPath, resp.data, 'base64');
RNFetchBlob.ios.previewDocument(fPath);
});https://stackoverflow.com/questions/67439415
复制相似问题