react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

Android 14: Error: Download manager download failed, the file does not downloaded to destination.

Open DmytroKlimchuk opened this issue 1 year ago • 16 comments

Package.json

    "react": "18.2.0",
    "react-native": "0.73.2",
    "react-native-blob-util": "0.19.4",

Build params:

        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"

When I try to download the file I get an error (Error: Download manager download failed, the file does not downloaded to destination.), but the file itself is downloading Z5OssD5

const BASE_DIR = Platform.OS === 'ios' ? RNFetchBlob.fs.dirs.CacheDir : RNFetchBlob.fs.dirs.DownloadDir;
const filePath = `${BASE_DIR}/${fileName}`;

const isExist = await RNFetchBlob.fs.exists(BASE_DIR);

if (isExist) {
  return RNFetchBlob.config({
        addAndroidDownloads: {
          useDownloadManager: true,
          notification: true,
          description: `${t('Downloading file')}...`,
          path: filePath,
          title: fileName,
          mediaScannable: true,
        },
        overwrite: true,
        fileCache: true,
        indicator: true,
        path: filePath,
      }).fetch(method, path, headers, body);
}

Logcat details: muUwhBr

DmytroKlimchuk avatar Jan 18 '24 14:01 DmytroKlimchuk

same issue any solution?

anastobe avatar Jan 22 '24 11:01 anastobe

facing same issue while downloading.....

danish5454 avatar Jan 22 '24 12:01 danish5454

Same issue here. It seems to fail only in Android 14.

marcelormourao avatar Jan 25 '24 02:01 marcelormourao

@marcelormourao no Its also fail on Android 13 devices as well. initially I'm facing Cannot read property 'rnfbEncode' of undefined to fix this I wrap the path with ReactNativeBlobUtil.wrap(path) but when downloading start its save on download folder but also its showing me Download manager download failed.

danish5454 avatar Jan 25 '24 04:01 danish5454

The same problem happened! But after downgrading to [email protected] based on this this Everything is working again! But still need to look into that issue.

imdangle avatar Jan 29 '24 05:01 imdangle

@dangleh Did you figured out any solution for this ?

NishantZet avatar Feb 05 '24 10:02 NishantZet

using 0.19.4 isn't working for me. I am getting same issue. File is downloaded, but getting the download manager error. I can see the file in the my app's download folder, but from the download manager pop-up it says "can't open file". I tried writing to root Download folder, but seeing same behavior. I have RN 0.73.3 and API Level = 33, means I should care about the permissions.

mollyOver avatar Feb 09 '24 07:02 mollyOver

version 0.19.8 also shave same issue

danish5454 avatar Feb 27 '24 05:02 danish5454

version 0.19.8 also shave same issue

Downgrading to version 0.19.4 worked for me, make sure you are now using ^for the package

NishantZet avatar Feb 27 '24 06:02 NishantZet

Having the issue with 0.19.4 too. The image is correctly downloaded but still have this error...

AntonyARHS avatar Apr 05 '24 07:04 AntonyARHS

@AntonyARHS can you share your package.json file?

NishantZet avatar Apr 05 '24 07:04 NishantZet

0.19.9 have same issue

usama-homage avatar Apr 15 '24 04:04 usama-homage

Can you try using react-native-blobl-util package instead of rn-fetch-blob as rn-fetch-blob is not maintained anymore.

export const onFileDownload = async (uri, callback) => {
  const fileName = uri?.split("/")?.pop();
  const { dirs } = RNBlobUtil.fs;
  const dirToSave = isIOS ? dirs.DocumentDir : "/storage/emulated/0/Download";
  const path = `${dirToSave}/${fileName}`;

  RNBlobUtil.config({
    fileCache: true,
    path: path,
    appendExt: "pdf",
    overwrite: true,
    addAndroidDownloads: {
      useDownloadManager: true,
      notification: true,
      mediaScannable: true,
      title: fileName,
      description: "Downloading file",
      path: path,
    },
  })
    .fetch("GET", uri)
    .then((res) => {
      if (isIOS) {
        callback && callback();
        RNBlobUtil.fs.writeFile(path, res.data, "base64");
        RNBlobUtil.ios.previewDocument(path);
      }

      if (isAndroid) {
        callback && callback();
        showToast("File downloaded");
      }
    })
    .catch((e) => {
      showToast(e?.message);
      console.log("file save ERROR", e.message);
    });
};

Haider-Ali-7 avatar Jun 03 '24 07:06 Haider-Ali-7