Navin Seab
Navin Seab

Reputation: 133

How to allow input file filed in swagger

I make a nest application and I try to make an endpoint that allows the user to upload the file and I want the upload file field to show in swagger. This is my function in Controller file:

    @Post('upload')
    @UseInterceptors(FileInterceptor('file'))
    uploadFile(@UploadedFile() file: Express.Multer.File) {
    console.log(file);
    }

But in my swagger UI , it doesn't show the upload file field enter image description here

Upvotes: 0

Views: 710

Answers (1)

Avi Siboni
Avi Siboni

Reputation: 814

Add the following decorator above the action

@ApiImplicitFile({ name: 'file' })

So instead of -

@Post('upload')
@UseInterceptors(FileInterceptor('file'))
uploadFile(@UploadedFile() file: Express.Multer.File) {
console.log(file);
}

change to -

  @ApiImplicitFile({ name: 'file' })
    @Post('upload')
    @UseInterceptors(FileInterceptor('file'))
    uploadFile(@UploadedFile() file: Express.Multer.File) {
    console.log(file);
    }

Upvotes: 1

Related Questions