[英]Expo Document Upload Is Not Working As Expected
I'm searching for a document uploader for my app and I got the expo document uploader.我正在为我的应用程序搜索文档上传器,我得到了博览会文档上传器。 But unfortunately when I'm going to test the app and nothings happens.
但不幸的是,当我要测试应用程序时,什么也没发生。 Kindly let me know the solution for this.
请让我知道此问题的解决方案。
https://snack.expo.io/S1HtdYQ1M https://snack.expo.io/S1HtdYQ1M
Your imports were outdated, importing ImagePicker from expo looks like this:您的导入已过时,从 expo 导入 ImagePicker 如下所示:
import * as ImagePicker from 'expo-image-picker';
Additionally, you were not requesting permissions.此外,您没有请求权限。 You should do so like this:
你应该这样做:
componentDidMount() {
this.getPermissionAsync();
}
getPermissionAsync = async () => {
if (Constants.platform.ios) {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status !== 'granted') {
alert('Sorry, we need camera roll permissions to make this work!');
}
}
};
Finally, if an async function seems to be doing nothing try wrapping it in a try/catch block so that you can see why it is failing as a failed promise does not always log correctly.最后,如果异步函数似乎什么都不做,请尝试将其包装在 try/catch 块中,以便您了解它失败的原因,因为失败的承诺并不总是正确记录。 Like this:
像这样:
_pickImage = async () => {
try {
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3],
});
if (!result.cancelled) {
this.setState({ image: result.uri });
}
} catch (e) {
console.log(e);
}
};
Most importantly, you should always consult the documentation when approaching an issue like this.最重要的是,在处理此类问题时,您应该始终查阅文档。 Expo's image picker documentation not only describes the above but gives you a working example.
Expo 的图像选择器文档不仅描述了上述内容,还为您提供了一个工作示例。
Here is a modified, working version of your snack 这是您的零食的修改后的工作版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.