2

我正在使用react-native-fetch-blob实现下载 PDF 文件。但我有一个错误“找不到变量:已收到

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

有什么想法或建议吗?提前致谢。

4

1 回答 1

0

progress函数需要得到一个函数,而不是两个变量作为参数。这是您需要更改为:

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)    
        })
}
于 2017-02-28T11:09:49.560 回答