- Upload was successful in the console.
const sendPost = () => {
const id = uuid();
const storage = getStorage();
const storageRef = ref(storage, `posts/${id}`)
const uploadTask = uploadString(storageRef, cameraImage, "data_url").then((snapshot) => {
console.log('Uploaded a data_url string')
});
}
- uploadTask.on is not a function (console error). I am trying to monitor the progress of the upload
uploadTask.on('state_changed', (snapshot) => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log("Upload is" + progress + "% done");
switch (snapshot.state) {
case "paused":
console.log("upload is runnig")
break;
}
})
- trying to logout errors, if any
(error) => {
switch (error.code) {
case "storage/unauthorized":
break;
case "storage/canceled":
break;
case "storage/unknown":
break;
}
},
- Trying to get the uploaded file URL and post it as a doc to firebase db
() => {
getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => {
addDoc(collection(db, "posts"), {
imageUrl: URL,
username: "swizz6ix",
read: false,
profilePic: user.profilePic,
timestamp: serverTimestamp(),
})
navigate("/chats")
})
}, );