我正在尝试删除 firebase 存储和 firestore 中的文档,但出现错误。我正在使用反应。
const onDelete = (e) => {
const { url } = e.target;
console.log("Url", url);
const deleteRef = ref(storage, url);
deleteObject(deleteRef)
.then(() => {
console.log("Item was deleted from Firebase Storage", deleteRef);
})
.catch((error) => {
console.log(error.message);
toast.error(error.message);
});
const imageDelete = db.collection("images").where("imageURL", "==", url);
imageDelete.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
doc.ref.delete();
});
console.log("Image should have been deleted from Firestore");
});
};
我得到的错误是:
Uncaught FirebaseError: Firebase Storage: The operation 'deleteObject' cannot be performed on a root reference, create a non-root reference using child, such as .child('file.png'). (storage/invalid-root-operation)
如错误消息所述,您正在尝试删除存储桶的根 - 这是不可能的。
从查看构建参考的代码来看,
url
似乎是空的,因此您需要检查从中获得的输出:
console.log("Url", url);