我在我的React Native应用程序中实现了一个文档选择器,在iOS上运行良好。但是在Android上,我遇到了一个奇怪的问题。
当我打开文档选择器并导航到Android手机中的文件浏览器(下载部分)时,虽然我能够选择PDF文件,但当回到应用程序时,它卡在页面上,文件不在那里。 我已经附加了截图。当文件浏览器到最近文件时,行为相同。只有当从最近文件中选择Google Drive并尝试从那里选择PDF时,它才按预期工作,并且我可以在我的应用程序中看到文件,应用程序不会卡住。
这是我编写的PDF文档选择器内容。
当我打开文档选择器并导航到Android手机中的文件浏览器(下载部分)时,虽然我能够选择PDF文件,但当回到应用程序时,它卡在页面上,文件不在那里。 我已经附加了截图。当文件浏览器到最近文件时,行为相同。只有当从最近文件中选择Google Drive并尝试从那里选择PDF时,它才按预期工作,并且我可以在我的应用程序中看到文件,应用程序不会卡住。
这是我编写的PDF文档选择器内容。
selectPDF = async ()=>{
var imageList = [...this.state.files];
try {
const results = await DocumentPicker.pickMultiple({
type: [DocumentPicker.types.pdf],
});
for (const res of results) {
console.log(
res.uri,
res.type, // mime type
res.name,
res.size
);
const fileName = res.uri.replace("file://","");
let data1 = ''
RnFetchBlob.fs.readStream(
fileName,
'base64',
4095
)
.then((ifstream)=>{
//let data1 = ''
ifstream.open()
ifstream.onData((data)=>{
data1 += data;
})
ifstream.onEnd(() => {
let base64 = data1
imageList.push({
imageName:res.name,
image:base64,
mime:res.type,
size:res.size
})
this.setState({
...this.state,
openCamera:false,
lastFileName:imageList[imageList.length - 1].imageName,
files:imageList
})
})
})
}
} catch (err) {
if (DocumentPicker.isCancel(err)) {
this.closeModal();
} else {
throw err;
}
}
}