question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Error: Download manager download failed, the file does not downloaded to destination.]

See original GitHub issue

I am trying to donwload image Here image do get to destination folder but the problem is it gives error saying

[Error: Download manager download failed, the file does not downloaded to destination.]

  • “react-native”: “0.63.0”, *“rn-fetch-blob”: “^0.12.0”

Code Snippets

const checkPermission = async (image: string) => {
    if (Platform.OS === 'android') {
      try {
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
          {
            title: 'Storage Permission Required',
            message: 'This app needs access to your storage to download Photos',
            buttonPositive: 'OK',
          },
        );
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
          console.log('Storage Permission Granted.');
          handleDownload(image);
        } else {
          Alert.alert('Storage Permission Not Granted');
        }
      } catch (err) {
        console.warn(err);
      }
    }
  };
  const getExtention = (filename: string) => {
    //To get the file extension
    return /[.]/.exec(filename) ? /[^.]+$/.exec(filename) : undefined;
  };

  const handleDownload = async (image: string) => {
    let date = new Date();
    let image_url = image;
    let ext = getExtention(image_url);
  
    const {config, fs} = RNFetchBlob;
    let pictureDir = fs.dirs.PictureDir;
    let options = {
      fileCache: true,
      addAndroidDownloads: {
        useDownloadManager: true,
        notification: true,
        path: 
         pictureDir +
         '/wallace_' +
         Math.floor(date.getTime() + date.getSeconds() / 2) +
        '.' +
         ext,
        description: 'Image',
      },
    };
    config(options)
      .fetch('GET', image_url)
      .then((res) => res.json())
      .then((res) => {
        console.log(res.path());
        Alert.alert('Image Downloaded Successfully.');
      })
      .catch((err) => {
        console.log(err);
        // Alert.alert('Download Failed', err.message);
      });
  };



Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

5reactions
sonisourabhcommented, Aug 22, 2020

I have also faced the similar issue i.e. write file on documentDir simply crashed for me. My project configuration is:

  • Android sdk 29
  • React Native 0.63.2

I found a workaround in Android documentation, which is, add android:requestLegacyExternalStorage="true" in AndroidManifest.xml file:

<application android:requestLegacyExternalStorage="true" ...

Reference: https://developer.android.com/reference/android/R.attr#requestLegacyExternalStorage

Hope that this will be useful for some of you who are struggling with crash/failure of rn-fetch-blob with Android sdk 29

3reactions
Jeyoung-Parkcommented, Jul 21, 2021

I solved it. In my case, there was a problem about filename.

image

As you can see, there are some special characters that are not allowed to use in filenames in android. The characters below are those. \ < > * " : ? \ |

this is my configOptions at first

const configOptions = Platform.select({
            ios: {
                path: RNFetchBlob.fs.dirs.DownloadDir+'/'+file.fileRealName
            },
            android: {
                addAndroidDownloads: {
                    useDownloadManager: true,
                    notification: true,
                    path: RNFetchBlob.fs.dirs.DownloadDir+'/'+file.fileRealName
                }
            }
        })

but there were problems when the filename contains \ < > * " : ? \ |. I think android download manager automatically change the characters above to _ and store in phone

so I changed the filepath like this(replace \ < > * " : ? \ | to _ in filePath

const regExp=/\/|<|>|\*|"|:|\?|\\|\|/g;

        const configOptions = Platform.select({
            ios: {
                path: RNFetchBlob.fs.dirs.DownloadDir+'/'+file.fileRealName.replace(regExp, '_')
            },
            android: {
                addAndroidDownloads: {
                    useDownloadManager: true,
                    notification: true,
                    path: RNFetchBlob.fs.dirs.DownloadDir+'/'+file.fileRealName.replace(regExp, '_')
                }
            }
        })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Download manager download failed the file does not ...
I am using rn-fetch-blob package to download file. ... Download manager donwload failed , the file does not downloaded to destination.
Read more >
Windows 11 problem with downloading files
I tried install something with Steam, Internet Download Manager and Chrome but all the downloads kept failing.
Read more >
FTP File error "Exception in Task - Forum - VisualCron
The error is "Exception in Task: Failed to download file" but when looking at the destination side of the download task I see...
Read more >
Akamai Download Manager FAQ - Adobe Support
Keep the web browser and the Akamai Download Manager 3 window open until the download completes. If you close either window prematurely, the ......
Read more >
PowerShell wget : Awesome Way to Download a File
Why not use PowerShell to download files much like an alternative ... file's location and the destination path to save the downloaded files....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found