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

Allow setting multer::Multipart constraints #1623

Open
martijnarts opened this issue Dec 7, 2022 · 5 comments
Open

Allow setting multer::Multipart constraints #1623

martijnarts opened this issue Dec 7, 2022 · 5 comments
Labels
A-axum C-feature-request Category: A feature request, i.e: not implemented / a PR. S-blocked Status: marked as blocked ❌ on something else such as a PR or other implementation work.

Comments

@martijnarts
Copy link

Feature Request

Motivation

I'm running into a length limit exceeded error from multer when trying to read a file coming in from a Multipart form. Multer supports Constraints to avoid this, but axum's multipart extractor does not allow forwarding these.

Proposal

I'm not super sure how this could be implemented, since the constraints can't be passed through the parameter typing. Either there might need to be some documented recommended way of parsing the request manually inside the handler, or maybe the multipart extractor needs to be a bit fancier to allow passing constraints.

Alternatives

For now, I'll "vendor" the Multipart extractor, since it seems simple enough, to add that functionality, but it seems like something axum's native extractor should support.

@martijnarts
Copy link
Author

I am willing to work on implementing this, btw!

@davidpdrsn
Copy link
Member

The limit you're running into is most likely https://docs.rs/axum/latest/axum/extract/struct.DefaultBodyLimit.html. It has a method to disable the default limit.

@martijnarts
Copy link
Author

You're right, after implement the vendored Multipart extractor I've realized Constraints are an opt-in thing. Thanks for linking that, I'll look into it.

Either way, it's probably not a bad idea to support these more specific constraints that multer exposes.

@davidpdrsn
Copy link
Member

Yeah I'm open to that.

However its a bit tricky since extractors can't really be configured currently, as they're types in function arguments. So if you have async fn handler(form: Multipart) how would you configure the Multipart? actix-web uses configs in their version of extensions but I'm not a fan of that approach since its very loosely typed. There is some more discussion about that here #1116

If one really needs the constraints today then I'd probably just recommend writing their own extractor that uses multer.

@davidpdrsn davidpdrsn added C-feature-request Category: A feature request, i.e: not implemented / a PR. A-axum labels Dec 7, 2022
@jplatte
Copy link
Member

jplatte commented Dec 7, 2022

I've created a POC for how we could support this eventually, once rust-lang/rust#95174 is stable.

@davidpdrsn davidpdrsn added the S-blocked Status: marked as blocked ❌ on something else such as a PR or other implementation work. label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-axum C-feature-request Category: A feature request, i.e: not implemented / a PR. S-blocked Status: marked as blocked ❌ on something else such as a PR or other implementation work.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants