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

Only one FilesInterceptor configuration per Controller possible #935

Closed
kiwikern opened this issue Aug 2, 2018 · 3 comments
Closed

Only one FilesInterceptor configuration per Controller possible #935

kiwikern opened this issue Aug 2, 2018 · 3 comments

Comments

@kiwikern
Copy link
Contributor

kiwikern commented Aug 2, 2018

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:

@kamilmysliwiec
Copy link
Member

Fixed in v5.2.0. Will publish soon

@kamilmysliwiec
Copy link
Member

5.2.0 is published!

@lock
Copy link

lock bot commented Sep 24, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants