When i creating my twitter clone with nextjs i got this error and it takes my 10 hours ,but luckily i got solution in my mind
my code was
const imageRef = ref(storage, `posts/${docRef.id}/image`);
//setselctedfile is an error
if(selectedFile){
await uploadString(imageRef, selectedFile ,"data_url").then(async()=>{
const downloadURL = await getDownloadURL(imageRef);
await updateDoc(doc(db, "posts", docRef.id),{
image:downloadURL
}
);
});
}
then i change updateDoc to onSnapshot
const imageRef = ref(storage, `posts/${docRef.id}/image`);
//setselctedfile is an error
if(selectedFile){
await uploadString(imageRef, selectedFile ,"data_url").then(async()=>{
const downloadURL = await getDownloadURL(imageRef);
await onSnapshot(doc(db, "posts", docRef.id),{
image:downloadURL
}
);
});
}
that's work for me .
Top comments (0)