【问题标题】:How to fix "Can't open file" in react-native(android) after file download with rn-fetch-blob?使用 rn-fetch-blob 下载文件后如何修复 react-native(android) 中的“无法打开文件”?
【发布时间】:2020-02-03 20:10:27
【问题描述】:

我正在使用 rn-fetch-blobreact-native (android) 中下载 PDF 文件。文件下载成功,但当我尝试打开时显示“无法打开文件”

RNFetchBlob.config({
    fileCache: true,
    appendExt : extension,
    addAndroidDownloads : {
        useDownloadManager: true,
        notification : true,
        path: DownloadDir + "/me_"+Math.random().toString().slice(2, 6) + '.' + extension,
        mime : 'application/pdf',
        mediaScannable : true,
    }
})
.fetch('GET',         'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'
          , { 'Cache-Control': 'no-store' })
        .then((res) => {
            alert('The file has saved!')
            console.log('The file saved to ', res)
        })

【问题讨论】:

    标签: android react-native


    【解决方案1】:

    将'android.permission.WRITE_EXTERNAL_STORAGE'添加到你的androidManifest.xml

    然后将其添加到您的代码中,

     const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
        )
        if (granted === PermissionsAndroid.RESULTS.GRANTED)
    

    看看,如果有帮助

    【讨论】:

    • 感谢您的回答这看起来很有趣,但实际上原因是我使用的是模拟器,而模拟器没有打开 pdf 文件的应用程序。
    猜你喜欢
    • 2019-12-03
    • 2017-11-22
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多