Im newbie to this tech, react native(android) and I cant find solution to my problem. My problem is, every time I pick an image my app will crash( this will happen if I use my samsung J7 prime, Android 6) But when I try my app to my Iphone 6s(IOS 15) and in my Samsung(Android 13), my codes is working. But I want also to run in my android 6.
This is what I've tried.
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
}); //get the image from library in local image
console.log(result);
if (!result.canceled) {
setGgcashProofImage(result.uri);
setFilenameInput(result.uri.split("/").pop());
}
};
const uploadImage = async () => {
const blob = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
resolve(xhr.response);
};
xhr.onerror = function () {
reject(new TypeError("Network request failed"));
};
xhr.responseType = "blob";
xhr.open("GET", gcashProofImage, true);
xhr.send(null);
});
const ref = firebase
.storage()
.ref()
.child("Customer_GcashProof/" + fileNameInput);
const snapshot = ref.put(blob, { contentType: "image/jpeg" });
snapshot.on(
firebase.storage.TaskEvent.STATE_CHANGED,
() => {
setUploadingImage(true);
//Alert.alert("Thank you uploading your Gcash proof of payment.")
// setShowModal_ModeOfPayment(false);
},
(error) => {
setUploadingImage(false);
console.log(error);
blob.close();
return;
},
() => {
snapshot.snapshot.ref.getDownloadURL().then((url) => {
setUploadingImage(false);
console.log("Download URL: ", url);
setgcashProoflink_Storage(url);
setGgcashProofImage(url);
blob.close();
Alert.alert("Thank you for uploading the image.");
return url;
});
}
);
};
const handleUploadImage=async()=>{
//check if the gcashProofImage if naa ba sulod or wala
if(gcashProofImage===null){
Alert.alert("Please upload a screenshot of your Gcash payment.");
}
else{
uploadImage();
}
}
Thank you.