Nest: Only one FilesInterceptor configuration per Controller possible

Created on 2 Aug 2018  ·  3Comments  ·  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


When two FilesInterceptors (multiple files!) are defined within one controller, only the last configuration options are applied. So when for the two endpoints two different fields are defined with @UseInterceptors(FilesInterceptor('first')) and @UseInterceptors(FilesInterceptor('second')), both will only accept second. It also doesn't work for a MulterOptions object like

@UseInterceptors(FilesInterceptor('first', null, {
    dest: './uploads/first'
  }))

It does work however for FileInterceptors (single file!) or when two different Controller are defined.

Expected behavior


The given configuration should be applied.

Minimal reproduction of the problem with instructions

Create a Controller with those two endpoints:

  @Post('first')
  @UseInterceptors(FilesInterceptor('first'))
  async uploadFirst(@UploadedFiles() files) {
    return files;
  }

  @Post('second')
  @UseInterceptors(FilesInterceptor('second'))
  async uploadSecond(@UploadedFiles() files) {
    return files;
  }

Make the following form-data POST requests to the given endpoint with a file in the given field:

| Endpoint | Field | Result | Expected |
| --- | --- | --- | --- |
| first | first | 400 - Unexpected field | Should work ❌ |
| first | second | 200 | Should not work ❌ |
| second | second | 200 | Should work ✔️ |

It might be the other way around: first works, second doesn't.

What is the motivation / use case for changing the behavior?


Came up in this Stackoverflow question.

Environment


Nest version: 5.1.2


For Tooling issues:
- Node version: v8.10.0 
- Platform: Windows  

Others:

common done 👏 type

Most helpful comment

Fixed in v5.2.0. Will publish soon

All 3 comments

Fixed in v5.2.0. Will publish soon

5.2.0 is published!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rafal-rudnicki picture rafal-rudnicki  ·  3Comments

cojack picture cojack  ·  3Comments

breitsmiley picture breitsmiley  ·  3Comments

tronginc picture tronginc  ·  3Comments

VRspace4 picture VRspace4  ·  3Comments