How to get one and many files in endpoint in nest.js

47 Views Asked by At

I need to get 10 images and 1 txt file in one endpoint in nest.js. Firstly I used 2 interceptors:

  @Post()
  @UseInterceptors(FilesInterceptor('images'), FileInterceptor('certificate'))
  async create(@Body() createProductDto: CreateProductDto, @UploadedFiles(ProductImageFilesPipe) images: Express.Multer.File[], @UploadedFile() certificate: Express.Multer.File) {
    return await this.productService.create(createProductDto, images, certificate);
  }

But every time I send request, I get enter image description here After that I tried to use this code:

  @Post()
  @UseInterceptors(FilesInterceptor([{
    name: "images", maxCount: 10
  },
    {
    name: "certificate", maxCount: 1
  }])
  async create(@Body() createProductDto: CreateProductDto, @UploadedFiles(ProductImageFilesPipe) images: Express.Multer.File[], @UploadedFile() certificate: Express.Multer.File) {
    return await this.productService.create(createProductDto, images, certificate);
  }

But it isn't compiled because of wrong type. Now I'm stuck and need help of brave Stack Overflowers)

0

There are 0 best solutions below