Experiencing the error message "delete(...).then(...).error is not a function" while attempting to remove a file from Firebase storage using AngularFire and TypeScript

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);
});

Answer №1

After encountering an issue, I found a solution by incorporating a promise obtained from RXJS into the delete() function before .then(). This seemed to resolve the problem, although it may just be a temporary fix that I'm uncertain about.

I am open to receiving any insights on this matter. :)

// Establishing a reference for the file to be deleted
  const desertRef = this.afStorage
    .ref(filePath)
    .child('cover_img_1040x585');
  // Deleting the file
  desertRef
    .delete()
    .toPromise() // INSERTED HERE
    .then((val) => {
      this.afStorage.upload(`${filePath}/cover_img`, this.coverFile);
      this.keepTrying(10, newFileRef).then((url) => {...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I configure Angular to redirect to an error page whenever an error is encountered in an HTTP API request?

With over 50 HTTP APIs in my application, I'm looking for a way to automatically route to a specific page whenever an error message or issue arises with one of the APIs. Instead of manually adding routing to each service, I want to find a simpler and ...

Unable to replicate the function

When attempting to replicate a function, I encountered a RootNavigator error Error in duplicate function implementation.ts(2393) I tried adding an export at the top but it didn't resolve the issue export {} Link to React Navigation options documen ...

Error in NextJS with TypeScript when updating data in a useState variable

Recently, I started working with TypeScript, ReactJS, and NextJS, but I encountered a TypeScript error that I need help fixing. My current project involves using NextJS 14, server actions, and Prisma as the ORM for a university-related project. An issue ar ...

Are you looking for a streamlined method to create styled components with MaterialUI?

I am exploring ways to easily define convenient components in my application utilizing Material-UI. After referring to an example from the Material-UI documentation for Appbar, I attempted to incorporate some React components for better readability. My c ...

The power of Ionic 2 combined with the Web Audio API

I am currently developing an Ionic 2 application that requires access to the user's microphone. When working on a web platform, I would typically use the following code snippet to obtain microphone access. navigator.getUserMedia = (navigator['ge ...

Determine the generic parameter of the output type by analyzing the resolved value of a data type within the function

I am looking to automatically determine the generic parameter of the return type by utilizing the resolved value of a type within the function. Consider the following: export type Context = any; export type Handler<T> = (ctx: Context) => Promise& ...

Displaying a React component within a StencilJS component and connecting the slot to props.children

Is there a way to embed an existing React component into a StencilJS component without the need for multiple wrapper elements and manual element manipulation? I have managed to make it work by using ReactDom.render inside the StencilJS componentDidRender ...

Is there a way to access the callback function's arguments and its return value from outside the function?

Is it possible to access both the callback function argument and the return value of a function that takes a callback function as an argument, outside of the function? Consider the following example with a function called func_a. function func_a(callback: ...

Checking for Object Equality in TypeScript

I'm working on a TypeScript vector library and encountered my first failed test. The issue revolves around object equality in TypeScript/JavaScript, and despite searching through TypeScript's official documentation (http://www.typescriptlang.org ...

Exploring Angular 10: Managing Two Promises in ngOnInit

I am currently working on integrating the Strava API into my Angular app. To summarize briefly: When a user clicks on a button to connect to Strava They are redirected to Strava for authentication (using PKCE) Strava then redirects back to my app with a ...

Redux-toolkit payload does not recognize the specified type

While working on my project, I encountered an issue when using redux-toolkit. I have created the following reducer: setWaypointToEdit: (state, action: PayloadAction<WaypointToEditPayload>) => { let gridPolygonsData: GridPolygonsData; const { ...

Encountering a 404 error when utilizing ngx-monaco-editor within an Angular application

I have been encountering an issue while attempting to utilize the editor within my Angular 8 application. Despite researching similar errors on Stack Overflow and GitHub discussions, I haven't found a solution yet. Here's how my angular.json asse ...

Error: The argument provided cannot be assigned to a parameter that requires a string type, as it is currently a number

Currently, I am in the process of migrating some older websites to TypeScript. However, I keep encountering a type error during the build process. The specific error message is Type error: Argument of type 'number' is not assignable to parameter ...

Struggling with intricate generic type mapping of records in Typescript

Whew...spent an entire day on this. My brain is fried... I am developing a type-safe mapper function that determines which props are needed based on the mapping type and can predict the output types based on the ReturnType. However, it seems like each re ...

Explain the functioning of the Node.js event loop and its ability to manage numerous requests simultaneously

Recently, I delved into testing asynchronous code in node.js. From what I understand, when there is an asynchronous operation taking place, Node.js should be able to handle new requests. Below is a snippet of code I wrote using express and axios: app.get(& ...

Transforming a TypeScript enum into an array of objects

My enum is defined in this structure: export enum GoalProgressMeasurements { Percentage = 1, Numeric_Target = 2, Completed_Tasks = 3, Average_Milestone_Progress = 4, Not_Measured = 5 } However, I want to transform it into an object ar ...

Creating a custom pipe that converts seconds to hours and minutes retrieved from an API can be achieved by implementing a transformation function

Can someone please provide guidance on creating a custom pipe in Angular 8 that converts seconds to hours and minutes? Thank you. <div class="col-2" *ngFor="let movie of moviesList"> <div class="movie"> {{ movie.attributes.title }} ...

"Encountering a 404 error with Firebase hosting custom domain when redirecting requests to Cloud

I've successfully set up an API on Google Cloud Functions at . However, I'm looking to create a more user-friendly domain name for the API. :) According to Google's documentation, this should be a straightforward process, but I'm encou ...

What could be causing the Error for the deprecated Class in Firestore SDK for PHP?

I recently updated to a newer version of 'google/cloud-firestore' and encountered an error. Here is the specific error message: Google\Cloud\Firestore\V1beta1\StructuredQuery_CollectionSelector is deprecated and will be ...

Parsing values from deeply nested objects and arrays

I've come across this issue before, but I'm having difficulty navigating through a nested structure. I can't seem to find any guidance in the right direction. Here is the object I'm attempting to parse: const nestedArray = { id ...