react-native-blob-util
react-native-blob-util copied to clipboard
Using Android download manager returns wrong path and empty file
When I use Android media manager to download file, and then try to use .path()
in copyToMediaStore
, it fails.
I investigated it a bit and that's what I found.
- The file is downloaded succesfully and if I tap on a download notification, I can open it. The path of this file is
content://com.android.providers.downloads.ui.fileprovider/cache-path/googlelogo_color_272x92dp-2.png
. The file is not visible in Photos app and probably remains somewhere in cache. - The
fetch
result containspath
and it's/data/user/0/com.android.providers.downloads/cache/googlelogo_color_272x92dp-2.png
-
.base64()
of the "fetch" result returns{"_h": 0, "_i": 0, "_j": null, "_k": null}
(but this could be not relevant to the issue) - When
MediaCollection.copyToMediaStore
is called with the.path()
mentioned above, it returnsNo such file '/data/user/0/com.android.providers.downloads/cache/googlelogo_color_272x92dp-2.png'; /data/user/0/com.android.providers.downloads/cache/googlelogo_color_272x92dp-2.png: open failed: ENOENT (No such file or directory)
If I use fetch
without addAndroidDownloads
option, it works okay and file is saved to media store.
Steps to reproduce:
ReactNativeBlobUtil.config({
addAndroidDownloads: {
useDownloadManager: true,
notification: true, // I know this is by default, just in case
},
})
.fetch('GET', 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
.then(async res => {
const path = res.path();
console.log('path: ', path);
console.log('base64: ', await res.base64());
let result = await ReactNativeBlobUtil.MediaCollection.copyToMediaStore(
{
name: 'test_file.png', // name of the file
parentFolder: '', // subdirectory in the Media Store, e.g. HawkIntech/Files to create a folder HawkIntech with a subfolder Files and save the image within this folder
mime: 'image/png',
},
'Download', // Media Collection to store the file in ("Audio" | "Image" | "Video" | "Download")
path, // Path to the file being copied in the apps own storage
);
});
- React Native version: 0.71.13
- react-native-blob-util version: 0.19.1
- Android: v13, 14 in emulator. Version 11 on a real device
For 3rd point, recheck the .base64() method, you might be printing a promise, just add an await before it.
My problem is with android download manager unable to handle post method requests for download. It just sends a get request without any body.
Hi @pid0r-3blan, i have the same issue with pdf files with the same exact scénarios, do you fond a solution to have have a valid file path when useDownloadManager is set to true ?
I'm experiencing the same problem, trying to fetch with useDownloadManager set to true and then attempting to copyToMediaStore - which results in the same error described above by @pid0r-3blan. Did anyone find any solution/workaround?
Facing the same issue here, was trying to preview the pdf file after download but hit with error on android
WARN Possible Unhandled Promise Rejection (id: 10):
Error: Failed to find configured root that contains /data/data/com.android.providers.downloads/cache/sample-18.pdf
ReactNativeBlobUtil.android.actionViewIntent(
res.path(),
'application/pdf',
);
Ref: https://github.com/RonRadtke/react-native-blob-util/issues/40#issuecomment-1846486304
I have the same issue. Have you come up with a solution for it?
Have the same Error right now. So frustrating..
This issue still exists. Anyone been able to solve it yet?😔
Facing same issue
Working path for both platform:
const {
dirs: { DownloadDir, DocumentDir },
} = ReactNativeBlobUtil.fs;
const fileDirPathAndroid = '/storage/emulated/0/Download';
const aPath = Platform.select({ ios: DocumentDir, android: fileDirPathAndroid });
const fPath = `${aPath}/${item?.docName}.${extension}`;