JulienHalgand's picture
Test container
19ec7d1
raw
history blame contribute delete
476 Bytes
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)