Implementation:Infiniflow Ragflow UseUploadDocument Hook
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Knowledge_Base |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Upload hook with auto-parse capability that handles file upload, optional automatic parsing, and unsupported file type detection.
Description
useHandleUploadDocument manages the document upload modal state and orchestrates the upload flow. On submit, it calls uploadDocument with the file list, then optionally triggers runDocumentByIds if parseOnCreation is true and the upload succeeded. It uses getUnSupportedFilesCount to detect partial failures where some file types are unsupported (HTTP 500 with partial success). The modal is hidden only when the effective result code is 0 (full or partial success). The hook returns loading state, modal visibility controls, and the submit handler.
Usage
Consumed by the dataset page upload button to handle the complete file upload workflow including validation and optional auto-parsing.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: web/src/pages/dataset/dataset/use-upload-document.ts
- Lines: 1-58
Signature
export const useHandleUploadDocument = () => {
documentUploadLoading, onDocumentUploadOk, documentUploadVisible,
hideDocumentUploadModal, showDocumentUploadModal,
};
Import
import { useHandleUploadDocument } from './use-upload-document';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | - | - | Hook manages state internally |
Outputs
| Name | Type | Description |
|---|---|---|
| onDocumentUploadOk | function | Submit handler accepting { fileList, parseOnCreation } |
| documentUploadLoading | boolean | Upload in progress |
| showDocumentUploadModal | function | Open upload dialog |
Usage Examples
const { showDocumentUploadModal, onDocumentUploadOk, documentUploadLoading } = useHandleUploadDocument();