Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using combination of @UploadedFile() and @UploadedFiles() decorators throws MulterError: Unexpected field #1619

Open
2 of 4 tasks
Yoronex opened this issue Apr 29, 2024 · 1 comment · May be fixed by #1620
Open
2 of 4 tasks

Comments

@Yoronex
Copy link

Yoronex commented Apr 29, 2024

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

The docs about file uploads suggest that it is possible to use a combination of @UploadedFiles() and @UploadedFile() 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 and no HTTP response is sent to the client (in Swagger UI, the endpoint loads forever).

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: 6.2.1
Version of NodeJS: 20.9.0

  • Confirm you were using yarn not npm: [x]

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.
PR #1541 implemented multiple files into separate fields, but the test case at

public async postWithDifferentFields(

only tests multiple fields with UploadedFile() (the singular, not the plural). Indeed, if I use two fields of the
singular version, the endpoint works fine.

Breaking change?

@Yoronex Yoronex linked a pull request Apr 29, 2024 that will close this issue
5 tasks
@Yoronex
Copy link
Author

Yoronex commented Apr 29, 2024

Implemented fix in #1620.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant