MCPcopy Create free account
hub / github.com/TAMustafa/Local_Chat_RAG / upload_file

Function upload_file

backend/app/main.py:116–133  ·  view source on GitHub ↗

Upload a file and ingest into the RAG pipeline. Delegates business logic to file_service. Validates file extension against SUPPORTED_EXTENSIONS.

(file: UploadFile = File(...), db: Session = Depends(get_db))

Source from the content-addressed store, hash-verified

114
115@app.post("/api/upload", response_model=FileUploadResponse)
116def upload_file(file: UploadFile = File(...), db: Session = Depends(get_db)) -> FileUploadResponse:
117 """
118 Upload a file and ingest into the RAG pipeline. Delegates business logic to file_service.
119 Validates file extension against SUPPORTED_EXTENSIONS.
120 """
121 ext = os.path.splitext(file.filename)[-1].lower()
122 if ext not in SUPPORTED_EXTENSIONS:
123 raise HTTPException(status_code=422, detail=f"Unsupported file type: {ext}")
124 db_file = upload_file_service(file=file, db=db)
125 # Ingest into RAG pipeline (kept here to avoid circular dependency)
126 try:
127 rag_pipeline.ingest(db_file.filepath, metadata={"file_id": db_file.id, "filename": db_file.filename})
128 except Exception as e:
129 db.delete(db_file)
130 db.commit()
131 os.remove(db_file.filepath)
132 raise HTTPException(status_code=500, detail=f"RAG ingestion failed: {str(e)}")
133 return FileUploadResponse(id=db_file.id, filename=db_file.filename)
134
135
136from app.services.file_service import list_files as list_files_service

Callers

nothing calls this directly

Calls 3

FileUploadResponseClass · 0.90
FileClass · 0.85
ingestMethod · 0.80

Tested by

no test coverage detected