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

# Blob 分块上传完成

> 本文档全面介绍 SquareCloud Blob API 的 PATCH /v1/objects/chunked 端点。

<ParamField header="Authorization" type="string" placeholder="API Key" required>
  你账户的 API 密钥。你可以在[账户设置](https://squarecloud.app/zh/account/security)中找到它。
</ParamField>

Chunked Complete 用于封存通过[分块初始化](/zh/blob-reference/endpoint/chunked-init)开启的上传：已存储的分块会被组装成最终对象，并在其公开 URL 上可用。你**不需要发送任何 ETag 或分块列表**，只需发送 `upload` 令牌；分块列表会从存储端读回，而存储端本身就是哪些分块已落地的权威数据源。

有两种失败情形会刻意让上传保持**开启**状态，以便你修复问题后重试 `PATCH`，而不必重新上传最多 1 GiB 的数据：`STORAGE_QUOTA_EXCEEDED`（释放空间后重试）和 `CHUNK_TOO_SMALL`（重新发送有问题的分块后重试）。而 `FILE_TOO_SMALL` 和 `FILE_TOO_LARGE` 则会直接中止上传。

速率限制为每 10 秒 5 次完成操作，因此多个并行上传可以同时完成。

<ParamField body="upload" type="string" placeholder="Upload token" required>
  由分块初始化返回的不透明 `upload` 令牌。

  ```json theme={null}
  { "upload": "UPLOAD_TOKEN" }
  ```
</ParamField>

### 响应

<ResponseField name="status" type="string">
  指示调用是否成功。成功为 "success"，否则为 "error"。
</ResponseField>

<ResponseField name="response" type="object">
  <Expandable title="展开对象">
    <ResponseField name="id" type="string">
      已存储对象的 ID（键）。
    </ResponseField>

    <ResponseField name="size" type="number">
      组装后对象的总大小，单位为字节。
    </ResponseField>

    <ResponseField name="parts" type="number">
      对象由多少个分块组装而成。
    </ResponseField>

    <ResponseField name="url" type="string">
      对象的公开 CDN URL。
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request PATCH \
    --url 'https://blob.squarecloud.app/v1/objects/chunked' \
    --header 'Authorization: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{ "upload": "UPLOAD_TOKEN" }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://blob.squarecloud.app/v1/objects/chunked', {
    method: 'PATCH',
    headers: {
      Authorization: 'YOUR_API_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ upload: uploadToken }),
  });
  ```

  ```python Python theme={null}
  import requests

  response = requests.patch(
      'https://blob.squarecloud.app/v1/objects/chunked',
      headers={'Authorization': 'YOUR_API_KEY'},
      json={'upload': upload_token},
  )
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "status": "success",
    "response": {
      "id": "3155597145698959364/myfile-ex30.fastq.gz",
      "size": 734003200,
      "parts": 22,
      "url": "https://public-blob.squarecloud.dev/3155597145698959364/myfile-ex30.fastq.gz"
    }
  }
  ```
</ResponseExample>

### 故障排查

<Tabs>
  <Tab title="400 状态码">
    ### 上传相关

    <CodeGroup>
      ```json INVALID_UPLOAD_TOKEN theme={null}
      // The upload token is missing, malformed, or does not belong to your account.
      {
          "status": "error",
          "code": "INVALID_UPLOAD_TOKEN"
      }
      ```

      ```json NO_CHUNKS_UPLOADED theme={null}
      // The upload has no stored chunks to assemble.
      {
          "status": "error",
          "code": "NO_CHUNKS_UPLOADED"
      }
      ```

      ```json CHUNK_TOO_SMALL theme={null}
      // A chunk other than the last is below 5 MB. The upload stays open:
      // re-send the offending parts, then retry the PATCH.
      {
          "status": "error",
          "code": "CHUNK_TOO_SMALL"
      }
      ```

      ```json FILE_TOO_SMALL theme={null}
      // The assembled object is below 512 bytes. The upload is aborted.
      {
          "status": "error",
          "code": "FILE_TOO_SMALL"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="401 状态码">
    ### 未授权

    <CodeGroup>
      ```json ACCESS_DENIED theme={null}
      // The API key is missing or invalid. Set a valid key in the Authorization header.
      {
          "status": "error",
          "code": "ACCESS_DENIED"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="403 状态码">
    ### 存储配额超限

    <CodeGroup>
      ```json STORAGE_QUOTA_EXCEEDED theme={null}
      // The account filled up while the parts were uploading. The upload is
      // LEFT OPEN: free space (or upgrade) and retry the PATCH, or abort it
      // with DELETE /v1/objects/chunked.
      {
          "status": "error",
          "code": "STORAGE_QUOTA_EXCEEDED"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="404 状态码">
    ### 未找到

    <CodeGroup>
      ```json UPLOAD_NOT_FOUND theme={null}
      // The upload was already completed, aborted, or expired.
      {
          "status": "error",
          "code": "UPLOAD_NOT_FOUND"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="413 状态码">
    ### 载荷过大

    <CodeGroup>
      ```json FILE_TOO_LARGE theme={null}
      // The assembled object exceeds 1 GiB. The upload is aborted.
      {
          "status": "error",
          "code": "FILE_TOO_LARGE"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="429 状态码">
    ### 速率受限

    <CodeGroup>
      ```json RATE_LIMITED theme={null}
      // Complete rate limit reached (5 requests per 10s window, blocked for 10s).
      {
          "status": "error",
          "code": "RATE_LIMITED"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="500 状态码">
    ### 上传失败

    <CodeGroup>
      ```json UPLOAD_FAILED theme={null}
      // Failed to assemble or register the object. If the message says to start
      // a new upload, the uploadId was consumed: open a new upload and send the
      // file again. Otherwise, retry the PATCH.
      {
          "status": "error",
          "code": "UPLOAD_FAILED"
      }
      ```
    </CodeGroup>
  </Tab>
</Tabs>
