MCPcopy Create free account
hub / github.com/OpenBMB/ChatDev / upload_attachment

Function upload_attachment

server/routes/uploads.py:10–35  ·  view source on GitHub ↗
(session_id: str, file: UploadFile = File(...))

Source from the content-addressed store, hash-verified

8
9@router.post("/api/uploads/{session_id}")
10async def upload_attachment(session_id: str, file: UploadFile = File(...)):
11 try:
12 manager = ensure_known_session(session_id, require_connection=False)
13 except ValidationError as exc:
14 raise HTTPException(status_code=400, detail=str(exc))
15 try:
16 record = await manager.attachment_service.save_upload_file(session_id, file)
17 except ValidationError:
18 raise HTTPException(status_code=400, detail="Session not connected")
19 except Exception as exc:
20 logger = get_server_logger()
21 logger.error(
22 "Failed to save attachment",
23 log_type=LogType.REQUEST,
24 session_id=session_id,
25 error=str(exc),
26 )
27 raise HTTPException(status_code=500, detail="Failed to store attachment")
28
29 ref = record.ref
30 return {
31 "attachment_id": ref.attachment_id,
32 "name": ref.name,
33 "mime_type": ref.mime_type,
34 "size": ref.size,
35 }
36
37
38@router.get("/api/uploads/{session_id}")

Callers

nothing calls this directly

Calls 4

ensure_known_sessionFunction · 0.90
get_server_loggerFunction · 0.90
save_upload_fileMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected