Proposal : make a synchronous form would be senseful! #8186
Replies: 6 comments
-
hey @newbie-tan , I'm not sure I get correctly what enhancement you want, but Forms are explained here: https://fastapi.tiangolo.com/tutorial/request-forms/ In this tutorial the function is async, but nothing prevents you from writing it synchronously removing the
|
Beta Was this translation helpful? Give feedback.
-
tks, butThe reality is that my front colleagues pass the information to the backend by using the form table all the place, i want to make it easy to packaging as a native python data structure.
it is my solution , help it work in a synchronous project |
Beta Was this translation helpful? Give feedback.
-
@tony-is-coding I imagine you want to use synchronous path operations. You can use normal And if you use files (https://fastapi.tiangolo.com/tutorial/request-files/#uploadfile) you can access |
Beta Was this translation helpful? Give feedback.
-
@tony-is-coding Is the point that you want to be able to access the result of async def get_form_data(request: Request):
return await request.form()
@router.post('/demo')
def get_file(form = Depends(get_form_data)):
file_text = form["file"].file._file.read().decode('utf-8')
path = "xxx"
and so on ...
return {"msg":"success"} FastAPI will evaluate the dependency asynchronously, then inject its result into the synchronous threadpool-based call to |
Beta Was this translation helpful? Give feedback.
-
Does that solve your use case @tony-is-coding ? |
Beta Was this translation helpful? Give feedback.
-
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues. |
Beta Was this translation helpful? Give feedback.
-
See as the title, and if has any solution, please give me some suggest, thinks!
Beta Was this translation helpful? Give feedback.
All reactions