fastapi icon indicating copy to clipboard operation
fastapi copied to clipboard

Added the ability to transfer Pydantic model to FormData

Open vobinics opened this issue 4 years ago • 4 comments

Fixed error 422 when creating Pydantic model from FormData. Example temporal workaround on StackOverflow

vobinics avatar Oct 06 '20 20:10 vobinics

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (e77ea63) 100.00% compared to head (e6ec56d) 100.00%. Report is 2321 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2139   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          239       240    +1     
  Lines         7079      7104   +25     
=========================================
+ Hits          7079      7104   +25     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Oct 06 '20 20:10 codecov[bot]

📝 Docs preview for commit e6ec56d2c992c4dd47de943af588cd60f9877cd6 at: https://5f7cddf0dd4b3c014cae6e71--fastapi.netlify.app

github-actions[bot] avatar Oct 06 '20 21:10 github-actions[bot]

Hey, I'd be interest to have this merged, is there anything blocking this to be merged ? Thank you !

Fkawala avatar Jul 12 '21 15:07 Fkawala

I tried


from fastapi import FastAPI, Form, Depends, UploadFile
from pydantic import BaseModel

app = FastAPI()


class SimpleModel(BaseModel):
    no: int = Form(...)
    nm: str = Form(...)
    f: UploadFile = Form(...)


@app.post("/form")
async def form_post(form_data: SimpleModel = Depends()):
    fp = await form_data.f.read()
    print(fp)

It works with current (0.86) version. Is this PR still needed?

iudeen avatar Nov 07 '22 22:11 iudeen