Skip to content
Discussion options

You must be logged in to vote

I think that it is not possible to use json body and file (image) upload in one handler. Because json is parsed as the whole request body (application/json) and file upload is implemented via multipart/formdata (also whole request body in different format)

I can suggest three possible solutions:

  1. Use different handler to attach images (prefered)
  2. Use a str field in ArticleCreate model and pass image with base64 encoding
  3. Use multipart/formdata for the whole request (article data + files: https://fastapi.tiangolo.com/tutorial/request-forms-and-files/)

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
6 participants
Converted from issue

This discussion was converted from issue #2959 on February 28, 2023 17:18.