rn-fetch-blob: [Error: Download manager failed to download from Status Code = 16]

Hi everyone

I try to download file and open it. For open i use FileViewr.opne(). To download i use :

options = {
                  addAndroidDownloads: {
                      fileCache: true,
                      useDownloadManager: true,
                      notification : true,
                      path: DownloadDir + pdfId + '.pdf'
                      description: 'Downloading file...',
                      overwrite : true,
                      title:"Health Records",
                      indicator:true
                  }

RNFetchBlob.config(options)
          .fetch('GET', fileUrl)
          .then((res) => {
               FileViewr.opne(res.data);
          }) 
          .then (()=>{
              console.log("")
          }) 
          .catch((error)=> console.log(error))

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 8
  • Comments: 32

Most upvoted comments

I’m facing this issue , I can download the file in chrome using the url , but in RNFB I get the statusCode=16

Finally, this worked for me

downloadFile = () => { if (this.isConnected) { const dirs = RNFetchBlob.fs.dirs; const android = RNFetchBlob.android RNFetchBlob.config({ fileCache: true, addAndroidDownloads: { useDownloadManager: true, mime: ‘application/pdf’, notification: true, mediaScannable: true, title: ‘test.pdf’, path: ${dirs.DownloadDir}/test.pdf }, }) .fetch(‘GET’, ‘https://download.novapdf.com/download/samples/pdf-example-encryption.pdf’, { ‘Cache-Control’: ‘no-store’ }) .then((res) => { if (Platform.OS = ‘android’) { android.actionViewIntent(res.path(), ‘application/pdf’) } }) .catch((e) => { console.log(e); }); } else { alert(‘Please check your internet connection’); } }

Unable to download the file getting status code 16 and only in android

@uendar well something is denying access. I had the same issue and that was because RNFetchBlob didn’t reuse the session cookie I got back using Fetch. I had to extract the session cookie manually and insert it as a header to the RNFetchBlob fetch.

Do you have any kind of authentication set up?

In my case i needed to pass the jwt token

 const {config, fs} = RNFetchBlob
  const PictureDir = fs.dirs.DownloadDir
  const options = {
    fileCache: true,
    addAndroidDownloads: {
      useDownloadManager: true,
      notification: true,
      title: nome,
      path: `${PictureDir}/${nome}.pdf`,
    },
  }
  const token = await getAccessToken()
  const res = await config(options).fetch('GET', `${REACT_APP_API}${uri}`, {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/pdf',
  })

@Maddumage are you sure about this part ? Platform.OS = 'android'

I believe Status Code 16 means authentication denied. Are you using cookies for authentication?