NarHakobyan/awesome-nest-boilerplate

Can't get the multiple uploaded files

swdreams opened this issue · 2 comments

I posted multiple files by form data. e.g. files[] = Array.

And I wanted to get them in my controller like the following:

@Post('upload')
  @Auth([])
  @HttpCode(HttpStatus.CREATED)
  @ApiFile({ name: 'files[]', isArray: true })
  async upload(@Body() createPostDto: Record<string, string>, @AuthUser() user: UserEntity, @UploadedFiles() files: IFile[]) {
    console.log('total files:', files.length);

    for (const [index, file] of files.entries()) {
      console.log(index, file.fieldname, file.originalname, file.size, file.mimetype);
    }

    // ...
  }

But unfortunately, it doesn't seem to work correctly. When I upload a file, I can get it properly.
Frontend: formdata: file: File
Backend: @apiFile({ name: 'file' })...

But for files array, it doesn't work. Could you advise on it?

Here are nestjs versions:

   "@nestjs/axios": "^0.0.7",
    "@nestjs/common": "^8.2.6",
    "@nestjs/config": "^1.1.6",
    "@nestjs/core": "^8.2.6",
    "@nestjs/cqrs": "^8.0.1",
    "@nestjs/jwt": "^8.0.0",
    "@nestjs/microservices": "^8.2.6",
    "@nestjs/passport": "^8.1.0",
    "@nestjs/platform-express": "^8.2.6",
    "@nestjs/serve-static": "^2.2.2",
    "@nestjs/swagger": "^5.1.5",
    "@nestjs/terminus": "^8.0.4",
    "@nestjs/typeorm": "^8.0.3",

Hi @NarHakobyan

Sorry for my mistake, I could get it working.
It works perfectly as I expect!

Thanks for your time.
Liki