Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download manager could not resolve downloaded file path #214

Open
Jeijie opened this issue Oct 19, 2018 · 12 comments
Open

download manager could not resolve downloaded file path #214

Jeijie opened this issue Oct 19, 2018 · 12 comments

Comments

@Jeijie
Copy link

Jeijie commented Oct 19, 2018

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
Copy link
Author

Jeijie commented Oct 19, 2018

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"
);
});

@mohammad-goldast
Copy link

same issue

@thejerrytan
Copy link

same here

@vitalyliber
Copy link

The same issue =(

@DonghyunNa
Copy link

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.

@mts88
Copy link

mts88 commented Apr 15, 2019

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

@TheAlmightyBob
Copy link

TheAlmightyBob commented Feb 27, 2020

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: wkh237#606)

@binotm25
Copy link

binotm25 commented Aug 8, 2020

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.

@spsingh559
Copy link

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.

@armendu
Copy link

armendu commented Feb 21, 2021

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

@abbasmoosavi
Copy link

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

@gift-sequoiaat
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests