from fastapi import FastAPI, UploadFile, File from fastapi.responses import FileResponse import os, shutil app = FastAPI() @app.get("/") def root(): return {"Hello": "World!"} @app.post("/upload") async def upload_file(file: UploadFile = File(...)): os.makedirs("uploads", exist_ok=True) filepath = f"uploads/{file.filename}" with open(filepath, "wb") as f: shutil.copyfileobj(file.file, f) return FileResponse(filepath, filename=file.filename)