**I’m using React native expo with fire-store and I’m trying to update and upload user image so when I open the album to select a photo then press update button I get this error **
Here is the Code
{/*fetch user data from firestore like name */}
React.useEffect (()=>{
const getUserData = async () => {
const auth = getAuth(app);
const docRef = doc(db,'users', auth?.currentUser?.uid)
const docSnap = await getDoc(docRef)
if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
setUserData(docSnap.data());
} else {
// docSnap.data() will be undefined in this case
console.log("No such document!");
}
{/*update user profile photo*/}
async function uploadImage (uri, fileType) {
const response = await fetch(uri)
const blob = await response.blob()
const sotrageRef = ref(storage, 'image/' + new Date().getTime())
const uploadTask = uploadBytesResumable(sotrageRef, blob)
//
uploadTask.on("state_change",
(snapshot)=> {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
console.log("progress", progress)
},
(error) => {
//handle error
},
() => {
getDownloadURL(uploadTask.snapshot.ref).then(async(getDownloadURL)=>{
console.log("File available at", getDownloadURL)
// save record
await saveRecord(fileType, getDownloadURL, new Date().toISOString())
setImage()
})
}
)
}
{/* function to save the file */}
const saveRecord = async (fileType,url, createAt) => {
const auth = getAuth(app)
const docRef = doc(db, "users", auth?.currentUser.uid,)
try {
// const docRef = await addDoc(collection(db, 'users'),{
await updateDoc(docRef,{
fileType,
url,
createAt,
});
console.log('document saved correctly', docRef.id)
} catch (error) {
console.log(error)
}
}
So please anyone knows which part or line in code cause problem and knows how to solve it please do help me out as I have spent hours on fixing this but I couldn’t. your help is extremely considered