# create_attachment_upload

> 這個 AirBuild MCP 工具會開始上傳要附加到訊息的檔案：它會傳回一次性上傳網址，以及傳送位元組的 curl 指令。

Source: https://air.build/tw/docs/mcp-tools/create_attachment_upload/

`create_attachment_upload` 會開始上傳你想附加到訊息的檔案。它會保留附件並傳回上傳網址；它本身不會傳輸任何位元組，因為 MCP 呼叫無法攜帶檔案。你以一次 HTTP `PUT` 傳送檔案，用 [complete_attachment_upload](https://air.build/tw/docs/mcp-tools/complete_attachment_upload/) 完成上傳，再用 [send_message](https://air.build/tw/docs/mcp-tools/send_message/) 附加它。附件屬於團隊，而不是某個頻道；在訊息中傳送之前，沒有人看得到它。

| 唯讀 | 破壞性 | 冪等 |
| --- | --- | --- |
| 否 | 否 | 否 |

## 上傳步驟

1. 以檔案的名稱、媒體類型和確切的位元組大小呼叫 `create_attachment_upload`。
2. 以一次 HTTP `PUT` 把檔案的位元組傳送到 `uploadUrl`，並把 `Content-Type` 標頭設為 `contentType`。`howTo` 欄位就是可以直接執行的這條指令：把 `<path-to-file>` 換成檔案路徑。上傳網址不需要 `Authorization` 標頭，在 `expiresAt` 之前都有效。
3. 以 `attachmentId` 呼叫 [complete_attachment_upload](https://air.build/tw/docs/mcp-tools/complete_attachment_upload/)。AirBuild 會檢查位元組是否與你宣告的相同。
4. 在 `attachmentIds` 中把 `attachmentId` 傳給 [send_message](https://air.build/tw/docs/mcp-tools/send_message/)。

## 輸入

| 輸入 | 類型 | 必填 | 預設值 | 作用 |
| --- | --- | --- | --- | --- |
| `teamId` | 字串（UUID） | 是 | — | 團隊，來自 [list_teams](https://air.build/tw/docs/mcp-tools/list_teams/) |
| `fileName` | 字串，1 到 255 個字元 | 是 | — | 大家看到的名稱，例如 `report.pdf`。不能包含 `/`、`\` 或控制字元，也不能是 `.` 或 `..` |
| `mediaType` | 字串，最多 255 位元組 | 是 | — | 檔案的媒體類型，例如 `image/png` 或 `application/pdf`。必須是具體的類型：`image/*` 會被拒絕。不知道類型時請使用 `application/octet-stream` |
| `byteCount` | 整數，至少為 1 | 是 | — | 檔案的確切位元組大小。上傳的內容必須剛好是這個大小 |

## 結果

| 欄位 | 說明 |
| --- | --- |
| `attachmentId` | 附件的 ID（UUID）。先傳給 [complete_attachment_upload](https://air.build/tw/docs/mcp-tools/complete_attachment_upload/)，再傳給 [send_message](https://air.build/tw/docs/mcp-tools/send_message/) |
| `uploadUrl` | `PUT` 位元組的目標位置 |
| `method` | `PUT` |
| `contentType` | `PUT` 必須帶有的 `Content-Type` 標頭：小寫的 `mediaType` |
| `expiresAt` | 上傳網址失效的時間（ISO 8601） |
| `howTo` | 執行 `PUT` 的 `curl` 指令 |

```json
{
  "attachmentId": "00000000-0000-0000-0000-000000000000",
  "uploadUrl": "https://<upload-host>/<path>",
  "method": "PUT",
  "contentType": "application/pdf",
  "expiresAt": "2026-11-21T09:30:00Z",
  "howTo": "curl -sS -X PUT -H 'Content-Type: application/pdf' --upload-file <path-to-file> 'https://<upload-host>/<path>'"
}
```

## 錯誤

_斜體_ 文字代表句中的實際值。

| 訊息 | 何時出現 | 處理方式 |
| --- | --- | --- |
| fileName is required. | 缺少 `fileName`，或只有空格 | 傳送檔案名稱 |
| byteCount is required. | 缺少 `byteCount` | 傳送檔案的位元組大小 |
| An Attachment must contain at least one byte. | `byteCount` 為 `0` | 空白檔案無法作為附件 |
| This file exceeds the _N_-byte limit. Choose a smaller file. | `byteCount` 超出團隊對單一檔案的上限 | 傳送較小的檔案，或將它分割 |
| Attachment fileName must contain 1...255 safe characters without path separators or control characters. | `fileName` 過長、是 `.` 或 `..`，或包含 `/`、`\` 或控制字元 | 傳送一般的檔案名稱 |
| Attachment mediaType must be a concrete IANA media type such as application/octet-stream. | `mediaType` 不是 `type/subtype` 格式，或使用了 `*` | 傳送實際的媒體類型，或 `application/octet-stream` |
| File uploads aren't available right now. Try again later. | 目前無法上傳。 | 稍後再試 |
| Unable to save this attachment right now. Try again. | AirBuild 無法記錄該附件 | 重試 |
| Team not found. | 團隊不存在，或你不在其中 | 使用 [list_teams](https://air.build/tw/docs/mcp-tools/list_teams/) 傳回的 `teamId` |

所有工具都可能傳回的錯誤，請參閱 [伺服器與登入](https://air.build/tw/docs/mcp-tools/server/#errors)。

## 範例

```json
{"name": "create_attachment_upload", "arguments": {"teamId": "00000000-0000-0000-0000-000000000000", "fileName": "report.pdf", "mediaType": "application/pdf", "byteCount": 482113}}
```
