Spaces:
Running
Running
File size: 589 Bytes
60ae242 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import FileResponse
import os
app = FastAPI()
UPLOAD_FOLDER = "uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
@app.post("/upload/")
async def upload(file: UploadFile = File(...)):
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
with open(file_path, "wb") as f:
f.write(await file.read())
return {"url": f"http://<your-server-ip>:8000/files/{file.filename}"}
@app.get("/files/{filename}")
async def get_file(filename: str):
return FileResponse(os.path.join(UPLOAD_FOLDER, filename))
|