Skip to content

Comments

Support IFormFile binding on complex [FromForm] models#2145

Merged
jeremydmiller merged 1 commit intomainfrom
GH1705
Feb 9, 2026
Merged

Support IFormFile binding on complex [FromForm] models#2145
jeremydmiller merged 1 commit intomainfrom
GH1705

Conversation

@jeremydmiller
Copy link
Member

Summary

  • Fixes Improve support for [FromForm] so that file uploads can be bound to complex models directly #1705: IFormFile and IFormFileCollection properties on complex models annotated with [FromForm] are now automatically bound from multipart form data
  • Previously, only direct method parameters of type IFormFile/IFormFileCollection were supported via FromFileStrategy. The FormBindingFrame that handles complex model property binding called TryFindOrCreateFormValue() for each property, which had no handling for file types — silently skipping them
  • Added ReadFormFileByName helper to HttpHandler that reads a form file by field name via IFormFileCollection.GetFile()
  • Added FormFilePropertyFrame and FormFileCollectionPropertyFrame code generation frames for property-level file binding
  • Updated FormBindingFrame to detect IFormFile/IFormFileCollection in both constructor parameters and settable properties
  • Also accepts multipart/form-data content type on all form data endpoints alongside application/x-www-form-urlencoded

Test plan

  • New test: bind_single_file_on_complex_model — verifies IFormFile property is bound with correct filename and length
  • New test: bind_file_collection_on_complex_model — verifies IFormFileCollection property is bound with correct file count
  • New test: bind_file_on_complex_model_when_no_file_sent — verifies IFormFile property is null when no file is sent
  • All existing from_form_binding tests pass (11 passed, 2 skipped due to pre-existing Alba limitation)
  • Full HTTP test suite: 463 passed, 4 pre-existing failures unrelated to this change

🤖 Generated with Claude Code

IFormFile and IFormFileCollection properties on complex models annotated with
[FromForm] are now automatically bound from multipart form data. Previously only
direct method parameters of these types were supported. Also accept multipart/form-data
content type on all form data endpoints alongside application/x-www-form-urlencoded.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve support for [FromForm] so that file uploads can be bound to complex models directly

1 participant