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

# 準備媒體資產上傳

> 建立 World Labs 媒體資產上傳目標

建立 World Labs 媒體資產記錄，並取得圖片或影片的上傳 URL。將二進位檔案上傳到 `upload_info.upload_url` 後，可在 `world_prompt` 中透過 `source: "media_asset"` 引用返回的 `media_asset.media_asset_id`。

TokenLab 會記錄資產歸屬。只有同一組織可以取得或在 World 生成中使用該媒體資產。

## 請求體

<ParamField body="file_name" type="string" required>
  原始檔名，最多 64 個字元。
</ParamField>

<ParamField body="kind" type="string" required>
  媒體類型：`image` 或 `video`。
</ParamField>

<ParamField body="extension" type="string">
  可選副檔名，例如 `png`、`jpg` 或 `mp4`。
</ParamField>

<ParamField body="metadata" type="object">
  隨上游媒體資產保存的可選中繼資料物件。
</ParamField>

## 回應

<ResponseField name="media_asset" type="object">
  已準備好的 World Labs 媒體資產中繼資料。
</ResponseField>

<ResponseField name="upload_info.upload_url" type="string">
  用於上傳二進位檔案的上游簽名 URL。
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/worlds/media-assets/prepare-upload" \
    -H "Authorization: Bearer sk-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "file_name": "reference.png",
      "kind": "image",
      "extension": "png"
    }'
  ```

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

  response = requests.post(
      "https://api.tokenlab.sh/v1/worlds/media-assets/prepare-upload",
      headers={"Authorization": "Bearer sk-your-api-key"},
      json={"file_name": "reference.png", "kind": "image", "extension": "png"},
  )

  print(response.json()["media_asset"]["media_asset_id"])
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.tokenlab.sh/v1/worlds/media-assets/prepare-upload', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer sk-your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ file_name: 'reference.png', kind: 'image', extension: 'png' })
  });

  const prepared = await response.json();
  console.log(prepared.media_asset.media_asset_id, prepared.upload_info.upload_url);
  ```
</RequestExample>
