I'm trying to implement the code snippet from Firebase documentation to delete a file and then upload a new image in the same directory on Firebase Storage. However, I keep encountering an error message saying "delete(...).then(...).error is not a function".
Below is the code I am using:
const filePath = `instructors/${instrcutorID}`;
// Create a reference to the resized image file
const newFileRef = this.afStorage.ref(`${filePath}/cover_img_1040x585`);
// Create a reference to the file that needs to be deleted
const desertRef = this.afStorage
.ref(filePath)
.child('cover_img_1040x585');
desertRef
.delete()
.then(() => {
this.afStorage.upload(`${filePath}/cover_img`, this.coverFile);
return this.keepTrying(10, newFileRef).then((url) => {
const coverURL = url;
this.afs.doc<Instructor>(`instructors/${instrcutorID}`).update({
coverURL: coverURL,
});
this.loadingSource.next(false);
alert('Successfully, updated...');
});
})
.catch((err: string) => {
this.loadingSource.next(false);
alert('Uh-oh, an error occurred!');
return console.error(err);
});