0

I need to download a created docx file.

the problem is it returns a corrupt xml which looks like this:

enter image description here

is it supposed to look like this and if so how do I convert it back to a docx file?

I read the documentation and implemented the following code

    @ApiResponse({
        schema: {
          type: 'string',
          format: 'binary',
        },
        status: HttpStatus.OK,
      })
    @UseGuards(JwtAuthGuard)
    @UsePipes(ParamValidationPipe)
    @Post('/report/:clientId')
    @Header('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
    @Header('Content-Disposition', 'attachment; filename="report.docx"')
    async createReport(
        @Req() req,
        @Res() res: Response,
        @Param('clientId') clientIdparam: ClientIdParam,
        @Body(DTOValidationPipe) createReportDTO: CreateReportDTO,
    ) {
        const buffer = await this.protocolServiceAdapter.createReport(
            req.user,
            createReportDTO,
            clientIdparam.id,
        );
        res.send(buffer);
    }

saving it with fs works fine

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

0 Answers0