FormData append is removing String qouts angular

107 Views Asked by At

when creating a formdata after appending data using .append() the value gets appended but after the value is send over HTTP the body is like

{ ProductName: Pname }

instead of { ProductName: "Pname" }

which in result is failing my JOI node validation in .string().

PS the reason of using FormData is i also need a file to be uploaded with the request.

1

There are 1 best solutions below

0
On
async create(@UploadedFiles() files, @Body() dto: any): Promise<any> {
    try {
        return await this.educationService.create(JSON.parse(dto.objectDto), files);
    } catch (e) {
        throw new HttpException(e.message, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

Try something like this you have to parse the object from frontend request because its content-type is form data(JSON.parse(dto.dto)).