> ## 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 の PUT /v1/objects/chunked エンドポイントの概要を包括的に説明します。

<ParamField header="Authorization" type="string" placeholder="API Key" required>
  アカウントの API キーです。これは[アカウント設定](https://squarecloud.app/ja/account/security)で確認できます。
</ParamField>

チャンクの送信 (Chunked Part) は、[チャンクの開始](/ja/blob-reference/endpoint/chunked-init)で開始したアップロードのチャンクを 1 つ送信します。ボディはチャンクの**生のバイト列**であり、multipart/form-data ではありません。パート番号は 1 から `max_parts` (205) までで、**任意の順序**で送信できます。失敗したパートは同じ番号でそのまま再送すればよく、パートは冪等なので再送しても安全です。

最後のチャンクを除くすべてのチャンクは **5 MB〜32 MB** である必要があり、最後のチャンクはこれより小さくても構いません。並列で送信するパートは最大 **6 つ**までにしてください。7 つ目の送信中パートは `TOO_MANY_CONCURRENT_CHUNKS` を返すため、その場合はいずれかの完了を待ってからそのパートを再試行します。6 パート並列であれば、ブラウザでは 16 MB のチャンクが適切なデフォルトです。

このルートはアカウント全体の API バジェット (`plan.rate`) の対象外なので、長時間のアップロードがプラットフォームの他の部分の API クォータを使い果たすことはありません。このルート独自のリミッターは 10 秒あたり 60 パートを許可し、超過すると 10 秒間ブロックされます。

<ParamField query="upload" type="string" placeholder="Upload token" required>
  チャンクの開始が返した不透明な `upload` トークン。
</ParamField>

<ParamField query="part" type="number" placeholder="1..205" required>
  パート番号 (1〜205)。パートは任意の順序で送信できます。
</ParamField>

<ParamField body="body" type="binary" required>
  チャンクの生のバイト列 (`Content-Type: application/octet-stream`)。multipart/form-data **ではありません**。
</ParamField>

### レスポンス

<ResponseField name="status" type="string">
  呼び出しが成功したかどうかを示します。成功した場合は "success"、失敗した場合は "error" です。
</ResponseField>

<ResponseField name="response" type="object">
  <Expandable title="オブジェクトを展開">
    <ResponseField name="part" type="number">
      保存されたパート番号。
    </ResponseField>

    <ResponseField name="size" type="number">
      保存されたチャンクのサイズ (バイト単位)。
    </ResponseField>

    <ResponseField name="etag" type="string">
      パートのストレージ ETag。情報提供のみです。完了処理はパート一覧をストレージから読み直すため、クライアントから送り返すことはありません。
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request PUT \
    --url 'https://blob.squarecloud.app/v1/objects/chunked?upload=UPLOAD_TOKEN&part=1' \
    --header 'Authorization: YOUR_API_KEY' \
    --header 'Content-Type: application/octet-stream' \
    --data-binary '@./chunk-1.bin'
  ```

  ```javascript JavaScript theme={null}
  const chunk = file.slice(0, 16 * 1024 * 1024); // first 16 MB

  const params = new URLSearchParams({ upload: uploadToken, part: '1' });

  const response = await fetch(`https://blob.squarecloud.app/v1/objects/chunked?${params}`, {
    method: 'PUT',
    headers: {
      Authorization: 'YOUR_API_KEY',
      'Content-Type': 'application/octet-stream',
    },
    body: chunk,
  });
  ```

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

  with open('./bigfile.bin', 'rb') as f:
      chunk = f.read(16 * 1024 * 1024)

  response = requests.put(
      'https://blob.squarecloud.app/v1/objects/chunked',
      headers={'Authorization': 'YOUR_API_KEY', 'Content-Type': 'application/octet-stream'},
      params={'upload': upload_token, 'part': 1},
      data=chunk,
  )
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "status": "success",
    "response": {
      "part": 1,
      "size": 16777216,
      "etag": "\"9bb58f26192e4ba00f01e2e7b136bbd8\""
    }
  }
  ```
</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 INVALID_CHUNK_PART theme={null}
      // The part number must be an integer between 1 and 205.
      {
          "status": "error",
          "code": "INVALID_CHUNK_PART"
      }
      ```

      ```json EMPTY_CHUNK theme={null}
      // The chunk body was empty.
      {
          "status": "error",
          "code": "EMPTY_CHUNK"
      }
      ```
    </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"
      }
      ```

      ```json PERMISSION_DENIED theme={null}
      // The account has no active paid plan. Uploading to Blob Storage requires a paid plan.
      {
          "status": "error",
          "code": "PERMISSION_DENIED"
      }
      ```
    </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 CHUNK_TOO_LARGE theme={null}
      // Each chunk accepts up to 32 MB.
      {
          "status": "error",
          "code": "CHUNK_TOO_LARGE"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="429 ステータスコード">
    ### レート制限

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

      ```json TOO_MANY_CONCURRENT_CHUNKS theme={null}
      // At most 6 chunks may be in flight at a time. Wait for one to finish, then retry this part.
      {
          "status": "error",
          "code": "TOO_MANY_CONCURRENT_CHUNKS"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="500 ステータスコード">
    ### アップロード失敗

    <CodeGroup>
      ```json UPLOAD_FAILED theme={null}
      // Failed to upload the chunk. Retry this part.
      {
          "status": "error",
          "code": "UPLOAD_FAILED"
      }
      ```
    </CodeGroup>
  </Tab>
</Tabs>
