> ## Documentation Index
> Fetch the complete documentation index at: https://docs-docflow.textin.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 文件拆分

## 功能概述

对于包含多份、多类别文件的复杂文档，文件拆分功能支持智能识别文档内容，实现文档的自动拆分及分类。

## 使用场景

### 1. 医疗保险理赔场景

一份多页文件包含：

* 第1-2页：保单信息
* 第3-5页：医疗发票
* 第6-10页：住院记录

通过文件拆分功能，可以将这三种不同类型的文档分别拆分出来，便于后续的分类和抽取处理。

### 2. 物流进出口场景

一份文件包含：

* 第1页：出口报关单
* 第2页：商业发票
* 第3页：装箱单(Packing List)
* 第4页：销售合同

<iframe src="https://dllf.intsig.net/download/2025/Solution/split_example.pdf" width="100%" height="600px" />

文件拆分功能可以按文档类型进行智能拆分。

## API 参数配置

### 启用文件拆分功能

在上传接口中设置 `split_flag=true` 来启用文件拆分功能：

```bash theme={null}
curl -X POST \
  -H "x-ti-app-id: <your-app-id>" \
  -H "x-ti-secret-code: <your-secret-code>" \
  -F "file=@/path/to/multi-page-document.pdf" \
  "https://docflow.textin.com/api/app-api/sip/platform/v2/file/upload?workspace_id=<your-workspace-id>&split_flag=true"
```

### 参数说明

| 参数名          | 类型      | 默认值   | 说明         |
| ------------ | ------- | ----- | ---------- |
| `split_flag` | boolean | false | 是否启用文件拆分功能 |

## 示例代码

<CodeGroup>
  ```python Python expandable theme={null}
  import requests
  import json

  def upload_with_split(file_path, workspace_id, app_id, secret_code):
      """
      上传文件并启用文件拆分功能
      """
      url = "https://docflow.textin.com/api/app-api/sip/platform/v2/file/upload"
      
      headers = {
          "x-ti-app-id": app_id,
          "x-ti-secret-code": secret_code
      }
      
      params = {
          "workspace_id": workspace_id,
          "split_flag": "true"  # 启用文件拆分功能
      }
      
      with open(file_path, 'rb') as file:
          files = {'file': file}
          response = requests.post(url, headers=headers, params=params, files=files)
      
      return response.json()

  def fetch_split_results(workspace_id, batch_number, app_id, secret_code):
      """
      查询文件拆分结果
      """
      url = "https://docflow.textin.com/api/app-api/sip/platform/v2/file/fetch"
      
      headers = {
          "x-ti-app-id": app_id,
          "x-ti-secret-code": secret_code
      }
      
      params = {
          "workspace_id": workspace_id,
          "batch_number": batch_number
      }
      
      response = requests.get(url, headers=headers, params=params)
      return response.json()

  # 使用示例
  if __name__ == "__main__":
      # 配置信息
      WORKSPACE_ID = "your-workspace-id"
      APP_ID = "your-app-id"
      SECRET_CODE = "your-secret-code"
      FILE_PATH = "/path/to/multi-page-document.pdf"
      
      # 上传文件并启用文件拆分
      upload_result = upload_with_split(FILE_PATH, WORKSPACE_ID, APP_ID, SECRET_CODE)
      print("上传结果:", json.dumps(upload_result, indent=2, ensure_ascii=False))
      
      # 获取批次号
      batch_number = upload_result.get("result", {}).get("batch_number")
      
      if batch_number:
          # 查询文件拆分结果
          fetch_result = fetch_split_results(WORKSPACE_ID, batch_number, APP_ID, SECRET_CODE)
          print("文件拆分结果:", json.dumps(fetch_result, indent=2, ensure_ascii=False))
  ```
</CodeGroup>

## 返回结果说明

### 文件拆分结果结构

当启用文件拆分功能后，`file/fetch` 接口返回的结果中会包含 `child_files` 字段，用于描述拆分后的子文档信息：

```json expandable theme={null}
{
  "code": 200,
  "result": {
    "files": [
      {
        "id": "parent-file-001",
        "name": "multi-document.pdf",
        "format": "pdf",
        "child_files": [
          {
            "id": "child-001",
            "task_id": "task-001",
            "task_type": 0,  // 0表示文件拆分产生的子文件
            "name": "multi-document.pdf#1",
            "format": "pdf",
            "category": "invoice",
          },
          {
            "id": "child-002", 
            "task_id": "task-002",
            "task_type": 0,
            "name": "multi-document.pdf#2",
            "format": "pdf",
            "category": "contract",
          }
        ]
      }
    ]
  }
}
```

### 关键字段说明

| 字段名                       | 类型      | 说明                       |
| ------------------------- | ------- | ------------------------ |
| `child_files`             | array   | 拆分后的子文件列表                |
| `child_files[].id`        | string  | 子文件唯一标识                  |
| `child_files[].task_type` | integer | 任务类型，0表示文件拆分产生           |
| `child_files[].category`  | string  | 文档分类结果                   |
| `child_files[].pages`     | string  | 拆分后的子文件页面信息，含子文件在原文件中的页码 |
