joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.83k stars 782 forks source link

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

Open uendar opened 6 years ago

uendar commented 6 years ago

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))
spock123 commented 6 years ago

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

uendar commented 5 years ago

No i am not

spock123 commented 5 years ago

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

canaan5 commented 5 years ago

any solution yet?

surendrapathak01 commented 5 years ago

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.

tmpbin commented 5 years ago

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

bockc commented 5 years ago

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

Maddumage commented 5 years ago

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

Maddumage commented 5 years ago

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

bockc commented 5 years ago

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

aathapa commented 5 years ago

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/

Ashkan-Oliaie commented 4 years ago

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

wincjh commented 4 years ago

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

jayrajkachariya commented 4 years ago

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

ganholete commented 4 years ago

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

willnaoosmith commented 4 years ago

same

prithweedas commented 4 years ago

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

TaraSinghDanu commented 3 years ago

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

ammarRajabA commented 3 years ago

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

Wangzihao5325 commented 3 years ago

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

meliodev commented 3 years ago

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

niknam-mohsen commented 3 years ago

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.

alvesrafa commented 3 years ago

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

ZeemZach commented 3 years ago

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

iqbalansyor commented 3 years ago

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

mMarcos208 commented 3 years ago

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',
  })
samy-tcheik commented 2 years ago

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

vicky123saini commented 2 years ago
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.

widianapw commented 1 year ago

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

JuliAnyday commented 11 months ago

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.

Chinmaymuduli commented 8 months ago

i am getting same issue with status code 16. The code is : ` const token = await AsyncStorage.getItem('accessToken'); const {config, fs} = RNFetchBlob; let DOCUMENT_DIR = fs?.dirs?.DownloadDir;

  let date = new Date();
  let options = {
    fileCache: true,
    trusty: true,
    addAndroidDownloads: {
      useDownloadManager: true,
      notification: true,
      title: 'Downloading....',
      path:
        DOCUMENT_DIR +
        '/Download' +
        Math.floor(date.getTime() + date.getSeconds() / 2) +
        '.xlsx',
      description: 'Downloading..',
    },
  };

  const response = await config(options).fetch(
    'POST',
    `${BASE_URL}/auth/bulk-export`,
    {
      'Content-Type': 'application/octet-stream',
      Authorization: `Bearer ${token}`,
    },
    JSON.stringify(myData),
  );

  const status = response.info().status;

  if (status === 200) {
    Toast.show({
      title: 'Success',
      description: 'File downloaded successfully',
      bgColor: COLORS.secondary,
    });
  } else {
    console.error('Failed to download file. Status:', status);
  }`
  Did anyone find any solutions to this?
durupanya commented 5 months ago

Hello everyone, this problem (Status Code = 16) in my case happens when android emulator is downloading a large file of 2MB and above.. But the physical phone downloads normally.

alexander0205 commented 1 month ago

something is denying acc

What was the solution @uendar ?