我正在尝试document picker
用于我的react-native
应用程序。我试过这个命令来安装文档选择器:npm i react-native-document-picker
. 编写一些代码后,我首先在网络浏览器上打开我的应用程序。但是当我尝试单击选择文件的按钮时,总是会发生此错误。有没有人有解决这个问题的方法?
非常感谢大家。下面是我的代码示例
import React from 'react';
import {
View,
Button,
} from 'react-native';
import DocumentPicker from 'react-native-document-picker';
export default function App() {
const openDocument = async () => {
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
});
console.log(
res.uri,
res.type, // mime type
res.name,
res.size
);
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
} else {
throw err;
}
}
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Button title="Choose file" onPress={() => openDocument()} />
</View>
);
}