Fast API Tutorial, Part 17: Request Files

preview_player
Показать описание
FastAPI is also capable of handling file uploads, which you'll definitely want to make available for certain use cases.

Check out how to do that using Form Data in this video.

Рекомендации по теме
Комментарии
Автор

the final error is because you were is hitting "/upload files/" instead of "/uploadfile/" in

<form action="/uploadfile/" enctype="multipart/form-data" method="post">

buczlfx
Автор

@app.post("/upload_files")
async def upload_file(file: UploadFile):
try:
if not os.path.exists("uploads"):
os.mkdir("uploads")
if
return {"file_exist": "file already in folder"}
with open(f"uploads/{file.filename}", 'wb') as f:
f.write(file.file.read())
except Exception as e:
return {"Other Error": str(e)}
check my endpoint for file upload

gooxmsb