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