React-native-fetch-blob: Android download manager fetch causes cookies to not be used

Created on 23 Nov 2017  ·  4Comments  ·  Source: wkh237/react-native-fetch-blob

Android download manager is failing to download, even though download succeeds without download manager.

  • please provide the version of installed library and RN project.

    • "react-native-fetch-blob": "^0.10.8",

  • a sample code snippet/repository is very helpful to spotting the problem.
    try { const res = await RNFetchBlob.config({ addAndroidDownloads: { useDownloadManager: true, mime: 'image/png', description: 'hiiii' } }) .fetch('GET', 'https://myseti.net/api/files/25844492-f7b7-4dcb-a9f7-4d65678ce6c7?version=original'); console.log('res:', res); } catch(ex) { console.warn('ex when downloading, ex:', ex); }

The above gives error:

"Error: Download manager failed to download from https://myseti.net/api/files/25844492-f7b7-4dcb-a9f7-4d65678ce6c7?version=original. Statu Code = 16"

https://github.com/wkh237/react-native-fetch-blob/blob/5f3c018b0a2b11246d1cce5b41f20634a2cf2d85/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java#L651

However this code works fine:

            const res = await RNFetchBlob.config({
                fileCache: true,
                appendExt: 'png'
            })
            .fetch('GET', 'https://myseti.net/api/files/25844492-f7b7-4dcb-a9f7-4d65678ce6c7?version=original');

But this does not use download manager. :(

Most helpful comment

any progress?

All 4 comments

Is it possible the cookies from the regular fetch call is not being used by the download manager? Is there a way to make it use the cookies? I tried this but it didnt help:

        const res = await RNFetchBlob.config(....)
        .fetch('GET', originalUrl, {
            'Set-Cookie': '................' // i added cookie here
        });

Here are the notifications that show after the above fails:

That one on the bottom with custom notification title is because i used the .config options to set a custom notif title.

Yes this was the problem. I had to do a dummy request, then set Cookie header in order for it to work:

    // dummy request to figure out cookie
    const resCookie = await fetchApi('session');
    if (resCookie.status !== 200) return alert('Failed to download, you must not be logged in anymore.');
    const cookie = resCookie.headers.map['set-cookie'][0];

    // download it
    const res = await RNFetchBlob.config({
        fileCache: true,
        addAndroidDownloads: {
            useDownloadManager: true,
            mime: mimeType,
            description
        }
    })
    .fetch('GET', originalUrl, { 'Cookie':cookie });

If i don't use the download manager, then the normal cookies used by normal fetch are also used by RNFetchBlob.fetch.

any progress?

Was this page helpful?
0 / 5 - 0 ratings