hi, I’m facing bug/warning while using imagePicker but it only 1 to 2 times after that works fine. I’m using expo managed workflow and expo imagePicker.
expo version: 4.2.1
platform: android
error: Unhandled promise rejection: TypeError: null is not an object (evaluating ‘image.localUri’)
const getImage = async () => {
// getting permission to access library
const permission = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (permission.granted === false) {
Alert.alert(
"Permission Required!",
"Permission to access library required!"
);
return;
}
// lunching library
const pickerResult = await ImagePicker.launchImageLibraryAsync({
mediaType: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [1, 1],
quality: 1,
});
if (pickerResult.cancelled === true) {
return;
}
// setting path
setImage({ uri: pickerResult.uri });
setLoading(true);
setTransfer(0);
const response = await fetch(image.uri);
const blob = await response.blob();
const imageName = image.uri.substring(image.uri.lastIndexOf("/") + 1);
const task = firebase
.storage()
.ref("userProfile")
.child(imageName)
.put(blob);
task.on("state_changed", (snap) => {
setTransfer(Math.round(snap.bytesTransferred / snap.totalBytes) * 100);
});
try {
await task.then(async (res) => {
await res.ref.getDownloadURL().then((res) => {
setPhotoUrl(res);
firebase.auth().currentUser.updateProfile({
photoURL: res,
});
firebase
.firestore()
.collection("userDetails")
.doc(firebase.auth().currentUser.uid)
.set({ image: res }, { merge: true });
});
});
setLoading(false);
setImage(null);
Alert.alert("Profile Updated", "Profile Updated Sucessfully");
} catch (error) {
Alert.alert(String(error.title), String(error.message));
}
};