我想要创建一个功能,使用户可以上传自己的个人资料图片并在React Native JavaScript中显示:
我可以使用expo-image-picker拾取和显示图像。
代码:
state = {
image: null,
};
componentDidMount() {
this.getPermissionAsync();
}
getPermissionAsync = async () => {
if (Platform.OS !== "web") {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status !== "granted") {
alert("Sorry, we need camera roll permissions to make this work!");
}
}
};
_pickImage = async () => {
try {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [12, 16],
quality: 1,
});
if (!result.cancelled) {
this.setState({ image: result.uri });
}
console.log(result);
} catch (E) {
console.log(E);
}
};
答案 0 :(得分:0)
您可以尝试将图像转换为base64格式,然后将其插入firebase。