Reputation: 167
I try to delete a image from firebase. I think that the problem is that I ain't get the URL. After refresh the the flatlist I get following warning:
"Possible Unhandled Promise Rejection (id: 1): Object {}"
This warning only displays when I refresh the flatlist after deleting a Item.
The "downloadURL" is the URL who I download when I upload the image to firebase. Is it that URL who I should try to get or I'am wrong?
export function deleteBoards(item) {
return (dispatch, getState) => {
return new Promise((resolve, reject) => {
firebase
.firestore()
.collection('coachboards')
.doc(auth().currentUser.uid)
.collection('userCoachboards')
.doc(item.id)
.delete()
.then((snapshot) => {
//Here I try to delete the image from firebase storage
storage()
.refFromURL(snapshot.data().downloadURL.url)
.delete()
.then(function () {
resolve();
})
.catch(function (error) {console.log(error)});
})
.catch(() => {
reject();
});
});
};
}
Updated result ✅
export function deleteBoards(item) {
return (dispatch, getState) => {
return new Promise((resolve, reject) => {
firebase
.firestore()
.collection('coachboards')
.doc(auth().currentUser.uid)
.collection('userCoachboards')
.doc(item.id)
.delete()
.then(() => {
//Here I try to delete the image from firebase storage
storage()
.refFromURL(item.downloadURL)
.delete()
.then(() => {
resolve();
})
.catch(error => {
reject();
});
})
.catch(() => {
reject();
});
});
};
}
Upvotes: 1
Views: 330
Reputation: 7388
As the error text says you are not handling the error case if the delete
fails. Try to add there an reject()
:
export function deleteBoards(item) {
return (dispatch, getState) => {
return new Promise((resolve, reject) => {
firebase
.firestore()
.collection('coachboards')
.doc(auth().currentUser.uid)
.collection('userCoachboards')
.doc(item.id)
.delete()
.then(() => {
//Here I try to delete the image from firebase storage
firebase.storage()
.refFromURL(item.downloadURL)
.delete()
.then( () => {
resolve();
})
.catch((error) => {
reject()
});
})
.catch(() => {
reject();
});
});
};
}
Can you also log this snapshot.data().downloadURL.url
value to see if it is correct.
Also shouldn't it be firebase.storage()
instead of just storage()
Upvotes: 1