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

Support Field Filter #875

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noonii
Copy link

@noonii noonii commented Apr 22, 2020

  • Equivalent to file filter, except for fields

Because multer parses FormData based on the order of inputted values, sometimes file is parsed before fields. Ideally, if we can filter fields and reject before file upload that would be best.

const formData = new FormData();
formData.append('file', file, file.name);
formData.append('field', 'value');

Even so, we want to filter/validate fields and abort if necessary.

EDIT: Can this be implemented for the deprecated and 2.0

@noonii
Copy link
Author

noonii commented Apr 22, 2020

@LinusU @jonchurch

@noonii
Copy link
Author

noonii commented May 1, 2020

@irfanfs you pinged the closed PR I made (accident)

This is the right PR. If they merge this I imagine they'd pub 1.4.3 too.

@irfanfs
Copy link

irfanfs commented May 1, 2020

@irfanfs you pinged the closed PR I made (accident)

This is the right PR. If they merge this I imagine they'd pub 1.4.3 too.

@noonii i want the bumped version of "mkdirp" to fix snyk vulnerability issue

@LinusU
Copy link
Member

LinusU commented May 1, 2020

@irfanfs

i want the bumped version of "mkdirp" to fix snyk vulnerability issue

run npm update mkdirp --depth=10 to bump your version of mkdirp


@noonii Would you mind expanding on the use case for this? None of the other express body parsers offers functionality to filter what goes into req.body as far as I know 🤔

Maybe this is better handled by a form validation library?

@noonii
Copy link
Author

noonii commented May 1, 2020

@noonii Would you mind expanding on the use case for this? None of the other express body parsers offers functionality to filter what goes into req.body as far as I know 🤔

Maybe this is better handled by a form validation library?

Server side validation.

Use case no. 1

  1. User populates formData with fields before files client side and calls api
  2. Multer parses fields before files
  3. fields parsed and throws validation error from filter
  4. operation aborted and data removed

Use case no. 2

  1. User populates formData with files before fields client side and calls api
  2. Multer parses files before fields
  3. files already stored in dir or stream
  4. fields parsed and throws validation error from filter
  5. operation aborted and data removed

Without the filter in all cases the file is uploaded to host and then leaving the app to validate and remove the file accordingly. The code to handle all of this efficiently exists in multer already, so it becomes redundant to the app. I suggest removing the redundancy.

Bonus: only in use case no.1 would it serve best because it handles aborting before the upload.

I run a service at scale that would benefit from this.

@panzi
Copy link

panzi commented Oct 1, 2021

If this field filter would also get the mime type of the field and could transform the value (i.e. the callback should get a 3rd parameter: the transformed value) than my pull request would be obsolete: #1037

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

Successfully merging this pull request may close these issues.

None yet

6 participants