File size: 476 Bytes
9d02239
 
19ec7d1
9d02239
 
 
 
19ec7d1
9d02239
 
 
 
 
19ec7d1
 
9d02239
19ec7d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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)