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