Implementation:Infiniflow Ragflow FileService Upload Document
| Knowledge Sources | |
|---|---|
| Domains | RAG, File_Management |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Concrete tool for uploading documents to a knowledge base provided by the RAGFlow FileService and DocumentService.
Description
The document upload flow involves two services: FileService.upload_document handles file storage to MinIO/S3 and returns file metadata, while DocumentService.insert creates the database record. The REST endpoint at api/apps/document_app.py orchestrates both operations within a single request, accepting multipart form data.
Usage
Call this when uploading files to an existing knowledge base. The endpoint accepts multipart form data with kb_id and one or more file attachments.
Code Reference
Source Location
- Repository: ragflow
- File: api/apps/document_app.py (endpoint), api/db/services/document_service.py (insert)
- Lines: L53-98 (endpoint), L352-358 (insert)
Signature
# REST endpoint
@manager.route('/upload', methods=['POST'])
@login_required
async def upload():
"""Upload documents to a knowledge base.
Form Data:
kb_id: str - Target knowledge base ID
file: FileStorage[] - Multipart file uploads
"""
# Service method
class DocumentService(CommonService):
@classmethod
@DB.connection_context()
def insert(cls, doc: dict) -> Document:
"""Insert a new document record.
Args:
doc: dict - Document metadata (id, kb_id, name, size, type, location, etc.)
Returns:
Document model instance
"""
Import
from api.db.services.document_service import DocumentService
from api.db.services.file_service import FileService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| kb_id | str | Yes | Target knowledge base ID |
| file | FileStorage[] | Yes | One or more file uploads (multipart) |
Outputs
| Name | Type | Description |
|---|---|---|
| documents | list[dict] | List of created document records with id, name, size, type, location, status |
Usage Examples
import requests
# Upload a document to a knowledge base
url = "http://localhost:9380/v1/document/upload"
files = {"file": open("report.pdf", "rb")}
data = {"kb_id": "kb-uuid-123"}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, files=files, data=data, headers=headers)
print(response.json())