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))
```
I believe Status Code 16 means authentication denied. Are you using cookies for authentication?
No i am not
@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?
any solution yet?
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.
use RNFetchBlob.fs.exists to make sure you path exists and writable before download.
@uendar
@surendrapathak01 I am in the same situation as you, did you find a solution ?
I am facing the same error again and again. Please help
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 are you sure about this part ? Platform.OS = 'android'
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/
I'm facing this issue , I can download the file in chrome using the url , but in RNFB I get the statusCode=16
+1
--edited--
i solved this issue.
mine was encoding problem.
@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?
Same problem. File returns in browser but error code 16 in app
same
Facing the same issue. Did anyone find any solutions to this?
Unable to download the file getting status code 16 and only in android
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
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
It happens also when you don't have enough memory space on your device.
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.
This problem only happens to me with an emulator. On a physical device this does not happen
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')
})
}
}
Most helpful comment
I'm facing this issue , I can download the file in chrome using the url , but in RNFB I get the statusCode=16