"react": "16.6.3",
"react-native": "0.57.8",
"rn-fetch-blob": "^0.10.15",
This is my PDFUtils.js, to handle PDF download/view in my app from a remote source. This code was working perfectly until some days ago.
Right now, this code is working perfectly as expected on iOS.
On Android, this still downloads the pdf, but with 2 unexpected behaviours:
response.respInfo.status is undefined!So I console-logged the response object, and I noticed that the android response object is changed!
ANDROID:

IOS:

I was looking for response.respInfo.status to see the statusCode of the network response, but this information is not available anymore on android only! Why??
Here is the code:
import { PermissionsAndroid, Platform } from 'react-native'
import RNFetchBlob from 'rn-fetch-blob'
import SHA1Generator from '../SHA1Generator'
import { URLKey, URLContest, URLDomain, baseURL } from 'react-native-dotenv'
import constants from '../../constants'
export const PDFDownloader = async queryParams => {
const dirs = RNFetchBlob.fs.dirs
// preparing url
const URLPath = URLContest + constants.endpoints.printPdfWorkingCareer.split(URLDomain)[0]
const SHA1Token = SHA1Generator(URLKey, URLPath)
const downloadURL = baseURL + constants.endpoints.printPdfWorkingCareer + SHA1Token + queryParams
if (Platform.OS === 'android') {
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
}
let destDir = ''
if (Platform.OS === 'ios') destDir = dirs.DocumentDir
else destDir = dirs.DownloadDir
destDir = destDir + '/LavoroXTe-PercorsoLavoratore.pdf'
const options = {
path: destDir,
fileCache: false,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
path: destDir,
title: 'LavoroXTe',
description: 'Downloading PDF...'
}
}
const config = {
'Content-Type': 'application/pdf',
'Cache-Control': 'no-store'
}
const response = await RNFetchBlob.config(options).fetch('GET', downloadURL, config)
console.log('pdfResponse: ', response)
if (response.respInfo.status !== 200) throw new Error('Download PDF error')
return destDir
}
Thanks in advance!
I had the same problem, I solved it by not using the download manager.
Most helpful comment
I had the same problem, I solved it by not using the download manager.