Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.7k
🐛 Fix validation error whenFile is declared afterForm parameter#11194
🐛 Fix validation error whenFile is declared afterForm parameter#11194tiangolo merged 4 commits intofastapi:masterfrom
File is declared afterForm parameter#11194Conversation
1763ed4 todcd2e69Compare This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
7e97f62 to0a1e865Comparethomasleveil commentedFeb 25, 2024
Thank you for the feed back. I pushed force with your suggested changes. Let me know if anything else can be improved. |
YuriiMotov left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The solution works.
Tests cover the issue. Tests fail before changes and pass after
cfreksen commentedNov 22, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I am wondering if this PR has been forgotten? I am not that familiar with the workflow in this repository, so excuse me if these things just take time or if this has low priority and there have been more important things to spend your time on. However, I was affected by#9116 which led me to this PR, and since it has some approvals and it hasn't been touched in 9 months, I thought it would be ok to "bump" it. |
carl-sauter commentedJun 20, 2025
Hey what about this pr? At least there should be a better error message. Wasted my time only for finding this. |
This comment was marked as resolved.
This comment was marked as resolved.
0a1e865 to4b6e747Compare This comment was marked as resolved.
This comment was marked as resolved.
577dce8 to150fb07Compare This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
50b9f22 toe34c53cCompare…t of a multipart/form-data request bodyThe HTTP specification for multipart/form-data, defined in RFC 7578, allows both form data and uploaded files in a single request. It does not require files to be before or after form fields.As such, no specific care is to be given to the first field.References:- [RFC 7578](https://datatracker.ietf.org/doc/html/rfc7578)- [FastAPI issue 9116](fastapi#9116)Closefastapi#9116
bb07937 to6e0abe9Comparethomasleveil commentedJun 23, 2025
@YuriiMotov here you go. |
YuriiMotov left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM!
File is declared afterForm parameter
tiangolo left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Great, thank you! 🚀 🙌
44fc676 intofastapi:masterUh oh!
There was an error while loading.Please reload this page.
This PR updates the fix (6185a92) from@jsg921019 so that tests pass with the latest FastAPI code (0.110.0).
It also adds a test to cover the case with multiple files, and another to ensure the order of parameters in an endpoint definition does not affect the way FastAPI handles the request.
Problem
When declaring an endpoint which accepts a
Filebut also aFormparameter, theFileparameter must be declared first or the endpoint would respond with error 422.Context