Why i'm getting this property in promise : body.__zone_symbol__value? Angular 16

Discussão em 'Angular' iniciado por user23755037, Novembro 17, 2024.

  1. user23755037

    user23755037 Guest

    I'll be simple this is a method to find any File type key in a formdata object, to save it in a indexed db.

    So, first i save the info like this: const data = item instanceof FormData ? await this.idb.serializeRequestBody(item) : item;

    items variable can be FormData or JSOn(stirng)

    Now, whits this functions I convert my file to base64 to make it readable on a img tag:

    public serializeRequestBody(body: FormData): any {
    try {

    const data: any = {};

    body.forEach(async (value, key) => {
    if (value instanceof File) {
    await this.fileToBase64(value).then((base64) => {
    data[key] = base64;
    });
    } else {
    data[key] = value;
    }
    });
    return data;

    } catch (error) {
    console.error('Error serializing request body:', error);
    throw error;
    }
    }

    private async fileToBase64(file: File): Promise<string> {
    try {
    const reader = new FileReader();
    return new Promise<string>((resolve, reject) => {
    reader.readAsDataURL(file);
    reader.onload = () => {
    resolve(reader.result as string);
    };
    reader.onerror = (error) => {
    reject(error);
    };
    });
    } catch (error) {
    console.error('Error converting file to Base64:', error);
    throw error;
    }
    }


    But I'm getting this:

    error image

    I add it like an image because the url is too long, I try to use promises, tryCatch, i search other solutions, and I did't found one that can help me.

    I hope anyone can guide me.!!

    Continue reading...

Compartilhe esta Página