dummy_end / app.py
05prey's picture
Update app.py
d85a16c verified
Raw History Blame Contribute Delete
925 Bytes
import time
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import HTMLResponse
api = FastAPI()
@api.get("/", response_class=HTMLResponse)
def home():
return """
<h2>Dummy Upload Sink</h2>
<p>POST a file to <code>/upload</code>.</p>
<pre>
curl -X POST https://YOUR_SPACE_URL/upload -F "file=@study.zip"
</pre>
"""
@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