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

# Quick Start

> Reference examples to quickly integrate document upload functionality with APIs

<Tip>
  This document demonstrates how to upload files to DocFlow through REST API. For more supported file formats, see [File Format Support](./support_format).
</Tip>

Docflow's business processing workflow is asynchronous. The upload interface can upload one or more files to Docflow. Once uploaded successfully, you will receive a batch code (`batch_number`) and several file identifiers (`file_id`) for subsequent business workflow queries and result retrieval.

Docflow supports common image formats, PDF, and Office file formats, with multi-page documents supporting up to **1000 pages**. You can refer to the more detailed [File Format Support and Limitations](./support_format) page.

## 01 Upload Single File

<CodeGroup>
  ```bash curl icon=terminal wrap 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/your/file.pdf" \
    "https://docflow.textin.ai/api/app-api/sip/platform/v2/file/upload?workspace_id=<your-workspace-id>"
  ```

  ```python Python expandable icon=python lines theme={null}
  import requests
  import os
  from requests_toolbelt.multipart.encoder import MultipartEncoder

  ti_app_id = "<your-app-id>"
  ti_secret_code = "<your-secret-code>"
  workspace_id = "<your-workspace-id>"
  filepath = "/path/to/your/file.pdf"

  host = "https://docflow.textin.ai"
  url = "/api/app-api/sip/platform/v2/file/upload"

  mime_type = "application/pdf"
  if filepath.lower().endswith((".jpg", ".jpeg", ".png")):
      mime_type = "image/jpeg"

  payload = MultipartEncoder(fields={
      "file": (os.path.basename(filepath), open(filepath, "rb"), mime_type)
  })

  resp = requests.post(
      url=f"{host}{url}",
      params={"workspace_id": workspace_id},
      data=payload.to_string(),
      headers={
          "Content-Type": payload.content_type,
          "x-ti-app-id": ti_app_id,
          "x-ti-secret-code": ti_secret_code,
      },
      timeout=60,
  )

  print(resp.status_code, resp.text)
  ```
</CodeGroup>

### Parameter Description

#### Required Parameters

* `workspace_id`: Workspace ID. Refer to the [Get Workspace ID](../100-faq/get_workspace_id) document.

#### Optional Parameters

Can be added to URL query parameters as needed:

* `category`: File category (e.g., invoice)
* `batch_number`: Batch number, automatically generated by the system when not provided (recommended: use the same batch number for multiple files in the same batch for easier querying)
* `split_flag`: Whether to perform file splitting, default false (see [File Splitting](../05-split/split) section)
* `crop_flag`: Whether to perform multi-image cropping, default false (see [Multi-Image Cropping](../05-split/crop) section)
* `target_process`: Target processing type, options are `classify` or `extract`.\
  Docflow will perform the complete workflow of parsing -> classification -> extraction by default. When `target_process` is `classify`, the workflow ends at classification to achieve **classification-only** requirements.

Example:

```bash curl icon=terminal wrap 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/invoice.pdf" \
  "https://docflow.textin.ai/api/app-api/sip/platform/v2/file/upload?workspace_id=<your-workspace-id>&category=invoice"
```

## 02 Batch Upload

When you want to associate multiple files to one batch, you can use batch upload.

There are two ways for batch upload:

1. Upload multiple files in one request. This approach is relatively simple, and you can implement batch upload by repeatedly including multiple `file` fields in the same request:

Example:

<CodeGroup>
  ```bash curl icon=terminal 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/1.pdf" \
    -F "file=@/path/to/2.pdf" \
    "https://docflow.textin.ai/api/app-api/sip/platform/v2/file/upload?workspace_id=<your-workspace-id>"
  ```

  ```python Python expandable icon=python lines theme={null}
  import requests
  import json
  from requests_toolbelt.multipart.encoder import MultipartEncoder
  import time

  ti_app_id = "your_app_id"
  ti_secret_code = "your_app_secret"
  workspace_id = "your_workspace_id"

  host = "https://docflow.textin.ai"
  epoch_time = int(time.time())
  http_method = "POST"
  url = "/api/app-api/sip/platform/v2/file/upload"
  params = {
      "workspace_id":workspace_id, 
      }

  payload = MultipartEncoder(
      fields=[
          ("file", ("file1.jpg", open("/path/to/file1.jpg", "rb"), "image/jpeg")),
          ("file", ("file2.jpg", open(filepath, "rb"), "image/jpeg")),
      ]
  )

  resp = requests.post(url=f"{host}{url}", 
                       params=params, 
                       data=payload_raw, 
                       headers={"Content-Type": payload.content_type,
                                "x-ti-app-id": ti_app_id,
                                "x-ti-secret-code": ti_secret_code,
                                })

  print(resp.text)
  resp_json = json.loads(resp.text)
  ```
</CodeGroup>

The response will return `result.batch_number` and a list of successfully uploaded `files`.

2. Upload through multiple requests, associating these files through `batch_number`.\
   When the total size of multiple files is too large, you can associate multiple files this way.
   The first request will return a `batch_number`, and subsequent requests reuse this `batch_number` to associate remaining files.

Example:

<CodeGroup>
  ```python Python expandable {35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50} icon=python lines theme={null}
  import requests
  import json
  from requests_toolbelt.multipart.encoder import MultipartEncoder
  import time
  import os

  ti_app_id = "your_app_id"
  ti_secret_code = "your_app_secret"
  workspace_id = "your_workspace_id"
  filepaths = ["/path/to/your/file1.png", "/path/to/your/file2.png"]

  host = "https://docflow.textin.ai"
  url = "/api/app-api/sip/platform/v2/file/upload"
  params = {
      "workspace_id":workspace_id, 
      }

  payload = MultipartEncoder(
      fields=[
          ("file", (os.path.basename(filepaths[0]), open(filepaths[0], "rb"), "image/png")),
      ]
  )

  resp = requests.post(url=f"{host}{url}", 
                       params=params, 
                       data=payload.to_string(), 
                       headers={"Content-Type": payload.content_type,
                                "x-ti-app-id": ti_app_id,
                                "x-ti-secret-code": ti_secret_code,
                                })

  print(resp.text)
  resp_json = json.loads(resp.text)

  # get and reuse `batch_number`
  batch_number = resp_json["result"]["batch_number"]
  params["batch_number"] = batch_number
  payload = MultipartEncoder(
      fields=[
          ("file", (os.path.basename(filepaths[1]), open(filepaths[1], "rb"), "image/png")),
      ]
  )

  resp = requests.post(url=f"{host}{url}", 
                       params=params, 
                       data=payload.to_string(), 
                       headers={"Content-Type": payload.content_type,
                                "x-ti-app-id": ti_app_id,
                                "x-ti-secret-code": ti_secret_code,
                                })

  print(resp.text)
  resp_json = json.loads(resp.text)
  ```
</CodeGroup>

## 03 Query Processing Results by Batch Number

After upload is complete, you can use `batch_number` to query processing results for that batch:

<CodeGroup>
  ```bash curl icon=terminal wrap theme={null}
  curl \
    -H "x-ti-app-id: <your-app-id>" \
    -H "x-ti-secret-code: <your-secret-code>" \
    "https://docflow.textin.ai/api/app-api/sip/platform/v2/file/fetch?workspace_id=<your-workspace-id>&batch_number=<your-batch-number>"
  ```

  ```python Python expandable icon=python lines theme={null}
  import requests
  import json

  ti_app_id = "<your-app-id>"
  ti_secret_code = "<your-secret-code>"
  workspace_id = "<your-workspace-id>"
  batch_number = "<your-batch-number>"

  host = "https://docflow.textin.ai"
  url = "/api/app-api/sip/platform/v2/file/fetch"

  resp = requests.get(
      url=f"{host}{url}",
      params={"workspace_id": workspace_id, "batch_number": batch_number},
      headers={"x-ti-app-id": ti_app_id, "x-ti-secret-code": ti_secret_code},
      timeout=60,
  )

  data = resp.json()
  for f in data.get("result", {}).get("files", []):
      print(f["id"], f.get("name"), f.get("recognition_status"), f.get("category"))
  ```
</CodeGroup>
