React Native View PDF-react-native-view-pdf-npm-从设备选择文件时不起作用-android

问题描述

我的应用程序中有文件选择器,因此已使用DocumentPicker从android设备中选择文件。 一旦我得到uri,它看起来就像

'content://com.android.providers.downloads.documents/document/10749'

我尝试将其加载到PDFView上,但它不呈现,也没有给出任何错误。我也尝试过使用RNFetchBlob在base64中转换文件的选项,然后查看它,但这也不起作用。

方法1-使用网址

const res = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],});
this.setState({
docPath: res.uri
})

render() {

<PDFView
fadeInDuration={100.0}
style={{borderWidth:1,flex:1}}
resource={docPath}
resourceType='url'
onLoad={() => console.log('loaded')}
onError={() => console.log('Cannot render PDF')}
/>

#Approach 2-使用base 64

const res = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],});

RNFetchBlob.fs.readFile(cleanUri,'base64')
// files will an array contains filenames
.then((files) => {
this.setState({
docPath: files
})
})

render() {

<PDFView
fadeInDuration={100.0}
style={{borderWidth:1,flex:1}}
resource={docPath}
resourceType='base64'
onLoad={() => console.log('loaded')}
onError={() => console.log('Cannot render PDF')}
/>
}

react和库的版本为:

"react-native-view-pdf": "^0.10.1","react": "16.11.0","react-native": "0.62.0",

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...