Open uendar opened 6 years ago
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')
})
}
}
I had the same issue in the real device, but after I disconnect my VPN, it successfully downloaded. Maybe it related with connection issue.
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',
})
i'm facing the same issu if anyone fixed the problem plz help
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.
i'm facing the same issue. Did anyone find any solutions to this?
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.
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?
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.
something is denying acc
What was the solution @uendar ?
Hi everyone
I try to download file and open it. For open i use FileViewr.opne(). To download i use :