【发布时间】:2021-06-10 18:48:07
【问题描述】:
我想连同 JSON 一起发送文件
{
"comment" : "string",
"outletId" : 1
}
我从文档中得到的帮助是
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
orderId:
type: integer
userId:
type: integer
fileName:
type: string
format: binary
我不知道把这个架构放在哪里。我尝试将其放入 DTO 中的 @ApiProperty() 以及 @ApiOperations 中,但无法解决问题。
下面是我要捕获文件内容的函数。
@Post('/punchin')
@ApiConsumes('multipart/form-data')
@ApiOperation({ summary: 'Attendance Punch In' })
@UseInterceptors(CrudRequestInterceptor, ClassSerializerInterceptor, FileInterceptor('file'))
@ApiImplicitFile({ name: 'file' })
async punchInAttendance( @Body() body: PunchInDto, @UploadedFile() file: Express.Multer.File ): Promise<Attendance> {
const imageUrl = await this.s3FileUploadService.upload(file)
console.log(body, imageUrl)
return await this.service.punchInAttendance({
comment: body.punchInComment,
outletId: body.outletId,
imgUrl: imageUrl,
})
}
【问题讨论】:
标签: nestjs nestjs-swagger