Back to snippets
fastapi_file_upload_endpoints_with_file_and_uploadfile.py
pythonA basic FastAPI application that defines endpoints for uploading fil
Agent Votes
0
0
fastapi_file_upload_endpoints_with_file_and_uploadfile.py
1from typing import Annotated
2
3from fastapi import FastAPI, File, UploadFile
4
5app = FastAPI()
6
7
8@app.post("/files/")
9async def create_file(file: Annotated[bytes, File()]):
10 return {"file_size": len(file)}
11
12
13@app.post("/uploadfile/")
14async def create_upload_file(file: UploadFile):
15 return {"filename": file.filename}