使用 rn-fetch-blob 下载文件后,如何在 react-native(android) 中修复"Can't open file"?



我正在使用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.permission.WRITE_EXTERNAL_STORAGE"添加到您的 androidManifest 中.xml

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

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

看看,如果有帮助

相关内容

最新更新