rnFetchBlob Error: Download manager failed to download from "url"

Published

i’m trying to download a pdf file from url but i’m getting this error
Error: Download manager failed to download from "myurl" status code=16
i can download the pdf file when i use the same url in chrome

    const downloadFile = (FILE_URL) => {

    const { config, fs } = RNFetchBlob;
    let RootDir = fs.dirs.PictureDir;
    let options = {
      fileCache: true,
      addAndroidDownloads: {
        path:
          RootDir+
          '/file_' + 
          Math.floor(date.getTime() + date.getSeconds() / 2) +
          file_ext,
        description: 'downloading file...',
        notification: true,
        useDownloadManager: true,   
      },
    };
    config(options)
      .fetch('GET', FILE_URL)
      .then(res => {
        setDownloading(false)
        console.log('res -> ', JSON.stringify(res));
        alert('Téléchargement terminé');
      });
  };
const checkPermission = async (FILE_URL) => {

if (Platform.OS === 'ios') {
  downloadFile(FILE_URL);
} else {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
      {
        title: 'Storage Permission Required',
        message:
          'Application needs access to your storage to download File',
      }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      downloadFile(FILE_URL);
      } else {
      Alert.alert('Error','Storage Permission Not Granted');
    }
  }
}

Source: Android Questions

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq