Home > Net >  When I try to upload an image with some additional data postman returns "Unexpected field"
When I try to upload an image with some additional data postman returns "Unexpected field"

Time:02-05

I am a self-learner. When I try to upload an image with some additional data postman returns this error... Has anyone any idea about this..?

enter image description here

This is my controller method :

 @Post()
  @UseInterceptors(FileInterceptor('file'))
  async create(
    @UploadedFile() file: Express.Multer.File,
    @Body() createItemDto: CreateItemDto,
  ) {
    console.log('item', createItemDto);
    console.log('file', file);
    // try {
    //   const item = await this.itemService.create(createItemDto);
    //   return {
    //     statusCode: HttpStatus.OK,
    //     message: 'Item created successfully',
    //     item,
    //   };
    // } catch (error) {
    //   return {
    //     message: error.detail,
    //   };
    // }
  }

My DTO : enter image description here

CodePudding user response:

The file option passed to the FileInterceptor is incorrect according to the postman request. It should be FileInterceptor('image') not FileInterceptor('file')

  •  Tags:  
  • Related