Skip to content

Conversation

Copy link

Copilot AI commented Jan 31, 2026

Extends the initial FromFiles/FromText implementation to support complex structured data in multipart forms. Users can now bind dataclasses with mixed regular fields, nested objects, and file uploads (bytes fields) with full type safety and automatic OpenAPI documentation.

Changes

  • Added FromMultipart[T] and MultipartBinder: New binder for complex multipart types with automatic form-to-object binding
  • OpenAPI schema generation: Introspects bound types and generates proper schemas where bytes fields → type: string, format: binary
  • Refactored _get_binder_by_type(): Extracted common pattern from _get_body_binder() and _get_files_binder() to reduce duplication

Example

from dataclasses import dataclass
from uuid import UUID
from blacksheep import Application, FromMultipart

@dataclass
class Address:
    street: str
    city: str

@dataclass
class UserProfile:
    id: UUID
    addresses: list[Address]
    avatar: bytes  # File upload

app = Application()

@app.router.post("/profile")
async def create_profile(data: FromMultipart[UserProfile]):
    # data.value.id is UUID
    # data.value.addresses is list[Address]
    # data.value.avatar is bytes from file upload
    return {"status": "created"}

Generated OpenAPI spec:

requestBody:
  content:
    multipart/form-data:
      schema:
        type: object
        properties:
          id:
            type: string
            format: uuid
          addresses:
            type: array
            items:
              $ref: '#/components/schemas/Address'
          avatar:
            type: string
            format: binary
Original prompt

Please continue the PR, working on the last comment I just wrote #652

Created from Copilot CLI via the copilot delegate command.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits January 31, 2026 07:09
Co-authored-by: RobertoPrevato <2576032+RobertoPrevato@users.noreply.github.com>
Co-authored-by: RobertoPrevato <2576032+RobertoPrevato@users.noreply.github.com>
Co-authored-by: RobertoPrevato <2576032+RobertoPrevato@users.noreply.github.com>
Copilot AI and others added 4 commits January 31, 2026 07:52
Co-authored-by: RobertoPrevato <2576032+RobertoPrevato@users.noreply.github.com>
Co-authored-by: RobertoPrevato <2576032+RobertoPrevato@users.noreply.github.com>
Co-authored-by: RobertoPrevato <2576032+RobertoPrevato@users.noreply.github.com>
Copilot AI changed the title [WIP] Continue work based on last comment in PR 652 Add FromMultipart[T] for complex structured multipart form data Jan 31, 2026
Copilot AI requested a review from RobertoPrevato January 31, 2026 08:01
@RobertoPrevato RobertoPrevato marked this pull request as ready for review January 31, 2026 13:01
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.

2 participants