import time from fastapi import FastAPI, UploadFile, File from fastapi.responses import HTMLResponse api = FastAPI() @api.get("/", response_class=HTMLResponse) def home(): return """
POST a file to /upload.
curl -X POST https://YOUR_SPACE_URL/upload -F "file=@study.zip"
"""
@api.post("/upload")
async def upload_sink(file: UploadFile = File(...)):
start = time.time()
total = 0
while True:
chunk = await file.read(1024 * 1024) # 1MB chunks
if not chunk:
break
total += len(chunk)
dt = time.time() - start
mb = total / (1024**2)
return {
"filename": file.filename,
"received_mb": round(mb, 2),
"duration_sec": round(dt, 2),
"throughput_mb_s": round(mb / dt, 2) if dt > 0 else 0.0,
}
# IMPORTANT: export this variable named `app`
app = api