Search code examples
react-nativereact-native-fetch-blob

React Native. "Can't find variable" error with react-native-fetch-blob


I'm implementing the downloading PDF file with react-native-fetch-blob. But I have an error "Can't find variable: received"

onPDFPressed(){        
    RNFetchBlob
        .config({
            notification: true,
            path: 'downloads/pdf_test.pdf',
            indicator: true,
            overwrite: true,
            addAndroidDownloads: {
                path: RNFetchBlob.fs.dirs.SDCardDir +'/downloads/pdf_test.pdf',
                useDownloadManager: true,
                notification: true,
                overwrite: true,
                description: 'downloading content...',
                mime: 'application/pdf',
                mediaScannable: false
            }
        })
        .fetch('GET', 'http://www.pdf995.com/samples/pdf.pdf')
        .progress(received, total)
    {
        console.log('progress', received / total)
    }
}

Any ideas or suggestions? Thanks in advance.


Solution

  • The progress function needs to get a function, not two variables as parameters. This is what you need to change to:

    onPDFPressed(){        
        RNFetchBlob
            .config({
                notification: true,
                path: 'downloads/pdf_test.pdf',
                indicator: true,
                overwrite: true,
                addAndroidDownloads: {
                    path: RNFetchBlob.fs.dirs.SDCardDir +'/downloads/pdf_test.pdf',
                    useDownloadManager: true,
                    notification: true,
                    overwrite: true,
                    description: 'downloading content...',
                    mime: 'application/pdf',
                    mediaScannable: false
                }
            })
            .fetch('GET', 'http://www.pdf995.com/samples/pdf.pdf')
            .progress((received, total) => {
                console.log('progress', received / total)    
            })
    }