Skip to content

Extracting request body as bytes #116

Answered by adriangb
danielkza asked this question in Q&A
Discussion options

You must be logged in to vote

There's a couple different ways to extract a body as bytes:

  • FromFile[UploadFile]: This will extract the entire request into an UploadFile and consume the request body. Note that unlike FastAPI this will not be a multipart request (that's handled using FromMultipart[SomeFormModel]).
  • FromFile[bytes]: This will extract directly into bytes but is otherwise the same as above.
  • FromFile[AsyncIterable[bytes]: this will give you a handle to the body stream (same as Request.stream())
  • Annotated[bytes, File(consume=False)]: this is probably what you want. It will extract the request body to bytes without consuming it. You could then use that with Annotated[SomePydanticModel, Json(consume=False)] to …

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@adriangb
Comment options

@danielkza
Comment options

Comment options

You must be logged in to vote
2 replies
@danielkza
Comment options

@adriangb
Comment options

Answer selected by danielkza
Comment options

You must be logged in to vote
1 reply
@adriangb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants