rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

[Error: Download manager failed to download from Status Code = 16]

Open uendar opened this issue 7 years ago • 34 comments

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))

uendar avatar Aug 29 '18 13:08 uendar

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

spock123 avatar Sep 12 '18 14:09 spock123

No i am not

uendar avatar Sep 21 '18 13:09 uendar

@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?

spock123 avatar Sep 21 '18 14:09 spock123

any solution yet?

canaan5 avatar Dec 28 '18 11:12 canaan5

I am facing the same issue but in my case, I have to send api-key in the header for authentication. I can not pull it off yet.

surendrapathak01 avatar Jan 04 '19 06:01 surendrapathak01

use RNFetchBlob.fs.exists to make sure you path exists and writable before download. @uendar

tmpbin avatar Feb 23 '19 09:02 tmpbin

@surendrapathak01 I am in the same situation as you, did you find a solution ?

bockc avatar Jul 01 '19 13:07 bockc

I am facing the same error again and again. Please help

Maddumage avatar Jul 20 '19 15:07 Maddumage

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'); } }

Maddumage avatar Jul 20 '19 16:07 Maddumage

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

bockc avatar Jul 23 '19 13:07 bockc

It seems you have not set path correctly. I faced similar issue and download manager does not create directory for me. Make sure your dir exists or set path to /storage/emulated/0/

aathapa avatar Aug 21 '19 07:08 aathapa

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

Ashkan-Oliaie avatar May 28 '20 03:05 Ashkan-Oliaie

+1 --edited-- i solved this issue. mine was encoding problem.

wincjh avatar May 29 '20 07:05 wincjh

@uendar In your case was file download successful and not able to open or couldn't download at all? @wincjh what kinda encoding problem? Can you please provide more details?

jayrajkachariya avatar Jul 06 '20 11:07 jayrajkachariya

Same problem. File returns in browser but error code 16 in app

ganholete avatar Jul 08 '20 11:07 ganholete

same

willnaoosmith avatar Aug 06 '20 11:08 willnaoosmith

Facing the same issue. Did anyone find any solutions to this?

prithweedas avatar Sep 09 '20 09:09 prithweedas

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

TaraSinghDanu avatar Sep 22 '20 07:09 TaraSinghDanu

Does this code mean that there's an error authenticating with backend or means there's no permission to download the file on the storage.

I have this issue only on a route where it needs an authentication token, although I'm passing the token and the headers right but the problem still occur.

Is there any way around this, or any other library that downloads a file from a protected route

ammarRajabA avatar Nov 04 '20 16:11 ammarRajabA

when i use https url ,release apk and debug apk both work well if i use http url ,debug apk is ok but release apk have Error: Download manager failed to download from Status Code = 16

Wangzihao5325 avatar Nov 19 '20 03:11 Wangzihao5325

It happens also when you don't have enough memory space on your device.

meliodev avatar Nov 30 '20 15:11 meliodev

This was a problem for me too. I used the following code : ` let fileDir = RNFetchBlob.fs.dirs.DownloadDir;

RNFetchBlob .config({ addAndroidDownloads: { useDownloadManager: true, title: productFile.Title, path: ${fileDir}/${productFile.Title}${productFile.Ext}, mediaScannable: true, notification: true, }, // this is much more performant. fileCache: true, indicator: true, overwrite: true }) .fetch('GET', productFile.Link) .then((res) => { ... }).catch((err) => { console.log(err); }) ` The cause of the problem was that the "productFile.Link" had to be encoded.

I Encode "productFile.Link" with UrlEncode method on the backend and problem was solved. I hope this is the reason for your problem too.

niknam-mohsen avatar Jan 14 '21 09:01 niknam-mohsen

This problem only happens to me with an emulator. On a physical device this does not happen

alvesrafa avatar Jan 20 '21 17:01 alvesrafa

I had the same issue "Status code 16" Bcoz of the actual file was not present at the url.

if (await isStoragePermitted()) { if(await isDirectoryOrCreate()){ RNFetchBlob .config({ fileCache: true, overwrite: true, indicator: true, addAndroidDownloads:{ useDownloadManager: true, notification: true, mediaScannable: true, mime: 'application/pdf', title: name, path : MOBILE_STORAGE + /${name} }, appendExt: 'pdf', }) .fetch('GET',link,{ 'Cache-Control': 'no-store' }) .then((res)=>{
console.log(res.path(),res.info())
Toast.show('File Downloaded')
}) }
}

ZeemZach avatar Mar 02 '21 08:03 ZeemZach

I had the same issue in the real device, but after I disconnect my VPN, it successfully downloaded. Maybe it related with connection issue.

iqbalansyor avatar Mar 26 '21 07:03 iqbalansyor

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',
  })

mMarcos208 avatar Apr 06 '21 16:04 mMarcos208

i'm facing the same issu if anyone fixed the problem plz help

samy-tcheik avatar Nov 29 '21 21:11 samy-tcheik

var date=new Date();
        const { config, fs } = RNFetchBlob
        let DownloadDir = fs.dirs.DownloadDir // this is the pictures directory. You can check the available directories in the wiki.
        
        let options = {
          fileCache: true,
          addAndroidDownloads : {
            useDownloadManager : true, // setting it to true will use the device's native download manager and will be shown in the notification bar.
            notification : true,
            path:  DownloadDir+"/file"+Math.floor(date.getTime() + date.getSeconds() / 2)+".pdf", //this is the path where your downloaded file will live in
            description : 'Downloading pdf.'
          }
        }
        config(options).fetch('GET', resp.data.pdf_url).then((res) => {
          // do some magic here
        });

work for me.

vicky123saini avatar Dec 29 '21 06:12 vicky123saini

i'm facing the same issue. Did anyone find any solutions to this?

widianapw avatar Aug 31 '23 06:08 widianapw

I also ran into this problem with the emulator. It almost seems random. Sometimes it works and sometimes it doesn't. I tried increasing the RAM usage of the emulator, but it made no difference.

I have tried everything I could find about this issue, but nothing works.

JuliAnyday avatar Sep 27 '23 11:09 JuliAnyday