lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.48k stars 498 forks source link

Upload multiple files using @UploadedFiles() and @UploadedFile causes multer error #1618

Closed Yoronex closed 5 months ago

Yoronex commented 5 months ago

Sorting

Expected Behavior

The docs about file uploads suggest that it is possible to use is possibly in the example.

  @Post("uploadFile")
  public async uploadFile(
      @FormField() title: string,
      @FormField() description: string,
      @UploadedFiles() files: Express.Multer.File[],
      @UploadedFile() file: Express.Multer.File,
  ): Promise<void> {
    console.log(files);
  }

Current Behavior

A multer error is thrown.

MulterError: Unexpected field
    at wrappedFileFilter (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\multer\index.js:40:19)
    at Multipart.<anonymous> (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\multer\lib\make-middleware.js:107:7)
    at Multipart.emit (node:events:514:28)
    at Multipart.emit (node:domain:488:12)
    at HeaderParser.cb (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\busboy\lib\types\multipart.js:358:14)
    at HeaderParser.push (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\busboy\lib\types\multipart.js:162:20)
    at SBMH.ssCb [as _cb] (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\busboy\lib\types\multipart.js:394:37)
    at feed (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\streamsearch\lib\sbmh.js:248:10)
    at SBMH.push (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\streamsearch\lib\sbmh.js:104:16)
    at Multipart._write (C:\Users\roy.kakkenberg\WebstormProjects\arvisan-backend\node_modules\busboy\lib\types\multipart.js:567:19) {
  code: 'LIMIT_UNEXPECTED_FILE',
  field: 'files',
  storageErrors: []
}

Possible Solution

Steps to Reproduce

  1. Copy the example from the TSOA docs to upload files into a controller class.
  2. Try to upload two files (one for each name).
  3. Multer throws an error.

Context (Environment)

Version of the library: Version of NodeJS:

Detailed Description

For my project, I wish to create and endpoint that takes multiple files as input. These files need to be organized, so I wish to use a combination of @UploadedFile and @UploadedFiles parameters for my endpoint.

Breaking change?

github-actions[bot] commented 5 months ago

Hello there Yoronex 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

Yoronex commented 5 months ago

Accidentally pressed enter, was not finished with writing the bug report.