I am trying to download an Excel Sheet given a Base64 string using RNFetchBlob, I'm able to download for android, SDK version 29, but when I try to download from android 11 it showing Error: Operation not permitted.

My code is:

downloading = (data, arrayBuffer) => {
    var date = moment()
        .utcOffset('+05:30')
        .format('YYYY-MM-DD hh:mm:ss');
    let docName = `Excel_${date}.xlsx`
    let pathToWrite = ''
    if (Platform.OS == 'ios') {
        const DownloadDir = RNFetchBlob.fs.dirs['MainBundleDir']
        const pathToDownload = `${DownloadDir}/${docName}`;
        pathToWrite = pathToDownload
    } else {
        pathToWrite = `${RNFetchBlob.fs.dirs.DownloadDir}/${docName}`;
    }
    let split = data.split('base64,')
    var mimeType = 'application/xlsx';
    RNFetchBlob.fs
        .writeFile(pathToWrite, split[1], 'base64')
        .then(() => {
            // alert(`${docName} Downloaded Successfully`)
            RNFetchBlob.android.addCompleteDownload({
                title: 'ChitNote' + date,
                description: 'Downloading FILE.',
                mime: mimeType,
                path: pathToWrite,
                showNotification: true,
                notification: true
            })
            alert(`Downloaded Successfully ${docName}`)
        })
        .catch((error) => {
            alert(error)
            console.log(error)
        });
}

Please help me to solve this issue.

0

There are 0 best solutions below