rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

download manager could not resolve downloaded file path

Open Jeijie opened this issue 6 years ago • 12 comments

When I downloaded apk by download manager, the error occurred. My code:
const android = RNFetchBlob.android; RNFetchBlob.config({ addAndroidDownloads: { useDownloadManager: true, title: "xxx.apk", description: "downloading", mime: "application/vnd.android.package-archive", mediaScannable: true, notification: true } }) .fetch("GET", appUrl) .then(res => { android.actionViewIntent( res.path(), "application/vnd.android.package-archive" ); });

Environment:

OS: Windows 7 Node: 8.12.0 Yarn: 1.9.4 npm: 6.4.1 Watchman: Not Found Xcode: N/A Android Studio: Not Found

"rn-fetch-blob": "^0.10.12"

Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: ^0.55.4 => 0.55.4

Jeijie avatar Oct 19 '18 02:10 Jeijie

after update code ,an error occurred.

Possible Unhandled Promise Rejection(id:0): Error:Attempt to invoke virtual method 'android.content.res.XmlResourceParser......

const android = RNFetchBlob.android; RNFetchBlob.config({ addAndroidDownloads: { useDownloadManager: true, title: "xxx.apk", description: "downloading...", mime: "application/vnd.android.package-archive", mediaScannable: true, path: RNFetchBlob.fs.dirs.DownloadDir + "/" + xxx.apk', notification: true } }) .fetch("GET", appUrl) .then(res => { console.warn('res...',res); android.actionViewIntent( res.path(), "application/vnd.android.package-archive" ); });

Jeijie avatar Oct 19 '18 03:10 Jeijie

same issue

mohammad-goldast avatar Oct 27 '18 05:10 mohammad-goldast

same here

thejerrytan avatar Oct 30 '18 09:10 thejerrytan

The same issue =(

vitalyliber avatar Nov 06 '18 08:11 vitalyliber

I use both of RNFS and RNFetchBlob.

I solved this problem with this solution

` var RNFS = require('react-native-fs'); import RNFetchBlob from 'rn-fetch-blob';

let downloadDest = ${RNFS.ExternalStorageDirectoryPath}/Download/123.jpg;

RNFetchBlob.config({ addAndroidDownloads: { useDownloadManager: true, path: downloadDest, notification: true, mime: '/' }).then((res) => { RNFetchBlob.android.actionViewIntent(res.path(), '/') }) `

It works to me. good luck.

DonghyunNa avatar Dec 17 '18 09:12 DonghyunNa

I use both of RNFS and RNFetchBlob.

I solved this problem with this solution

` var RNFS = require('react-native-fs'); import RNFetchBlob from 'rn-fetch-blob';

let downloadDest = ${RNFS.ExternalStorageDirectoryPath}/Download/123.jpg;

RNFetchBlob.config({ addAndroidDownloads: { useDownloadManager: true, path: downloadDest, notification: true, mime: '/' }).then((res) => { RNFetchBlob.android.actionViewIntent(res.path(), '/') }) `

It works to me. good luck.

Worked for me! Thanks

mts88 avatar Apr 15 '19 11:04 mts88

This is due to a bug in RNFetchBlobReq.java's onReceive.

It throws this error if path was not provided and it has not retrieved a filePath from the DownloadManager result:

if (options.addAndroidDownloads.hasKey("path")) {
...
}
else {
    if(filePath == null)
        this.callback.invoke("Download manager could not resolve downloaded file path.", RNFetchBlobConst.RNFB_RESPONSE_PATH, null);
    else
        ...
}

However, it does not bother trying to retrieve filePath (even though it is available) unless mime was set and it was set to image:

if ( contentUri != null &&
        options.addAndroidDownloads.hasKey("mime") &&
        options.addAndroidDownloads.getString("mime").contains("image")) {
    Uri uri = Uri.parse(contentUri);
    Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
    // use default destination of DownloadManager
    if (cursor != null) {
        cursor.moveToFirst();
        filePath = cursor.getString(0);
        cursor.close();
    }
}

I don't have time to submit a PR right now, but I believe this would be trivial to fix by changing the logic to:

if ( contentUri != null ) {
    Uri uri = Uri.parse(contentUri);
    Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Files.FileColumns.DATA}, null, null, null);

The path check in that first code snippet is why adding that property to your config can work around the issue.

(also this was previously reported in the original project: https://github.com/wkh237/react-native-fetch-blob/issues/606)

TheAlmightyBob avatar Feb 27 '20 00:02 TheAlmightyBob

I fixed this issue by including the path inside the addAndroidDownloads object.

RNFetchBlob.config({ fileCache : true, path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', addAndroidDownloads : { notification : true, useDownloadManager: true, title : 'test-report-'+data.id+'.pdf', mime : 'application/pdf', description : 'Your test reports.', path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here } })

After that the res.path() returns the right location and I can open the pdf file which I have downloaded.

binotm25 avatar Aug 08 '20 19:08 binotm25

I fixed this issue by including the path inside the addAndroidDownloads object.

RNFetchBlob.config({ fileCache : true, path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', addAndroidDownloads : { notification : true, useDownloadManager: true, title : 'test-report-'+data.id+'.pdf', mime : 'application/pdf', description : 'Your test reports.', path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here } })

After that the res.path() returns the right location and I can open the pdf file which I have downloaded.

There is no need to add path and file cache in config field, Download manager ignore both the fields. Having path defined in addAndroidDownloads is enough to work.

spsingh559 avatar Aug 20 '20 10:08 spsingh559

I fixed this issue by including the path inside the addAndroidDownloads object.

RNFetchBlob.config({ fileCache : true, path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', addAndroidDownloads : { notification : true, useDownloadManager: true, title : 'test-report-'+data.id+'.pdf', mime : 'application/pdf', description : 'Your test reports.', path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here } })

After that the res.path() returns the right location and I can open the pdf file which I have downloaded.

this one worked for me. Thank you very much

armendu avatar Feb 21 '21 21:02 armendu

I fixed this issue by including the path inside the addAndroidDownloads object.

RNFetchBlob.config({ fileCache : true, path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', addAndroidDownloads : { notification : true, useDownloadManager: true, title : 'test-report-'+data.id+'.pdf', mime : 'application/pdf', description : 'Your test reports.', path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here } })

After that the res.path() returns the right location and I can open the pdf file which I have downloaded.

Nice, safe my time, thank you

abbasmoosavi avatar Jul 16 '21 08:07 abbasmoosavi

I fixed this issue by including the path inside the addAndroidDownloads object. RNFetchBlob.config({ fileCache : true, path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', addAndroidDownloads : { notification : true, useDownloadManager: true, title : 'test-report-'+data.id+'.pdf', mime : 'application/pdf', description : 'Your test reports.', path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here } }) After that the res.path() returns the right location and I can open the pdf file which I have downloaded.

Nice, safe my time, thank you

This solution works thanks

gift-sequoiaat avatar Jun 22 '23 11:06 gift-sequoiaat