For the complete documentation index, see llms.txt. This page is also available as Markdown.

附件與檔案

建立新附件 (整合)

POST /api/v1/attachments-upload/

程式碼範例

# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/attachments-upload/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -F "file=@example_file.pdf"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
const axios = require('axios');
const FormData = require('form-data');

// 建立FormData對象
const formData = new FormData();
// 請用實際檔案替換
formData.append('file', /* 實際檔案物件 */, 'example_file.pdf');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    ...formData.getHeaders()
  }
};

axios.post("https://api.maiagent.ai/api/v1/attachments-upload/", formData, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });

回應內容

狀態碼: 201

回應結構範例

{
  "id": string (uuid)
  "type"?:  // 非必填
  {
  }
  "filename": string
  "file": string (uri)
  "expiresAt": string // ISO datetime when this attachment will be auto-deleted.

For conversation-bound attachments: conversation.last_message_created_at + retention_days.
For attachments without a conversation: created_at + retention_days.
Returns None when cleanup is disabled (effective_from not set).
}

回應範例值


取得檔案上傳用的預簽署 URL

POST /api/v1/upload-presigned-url/

請求內容

請求參數

欄位
類型
必填
說明

modelName

string

是

模型名稱,例如 attachment、web-chat、faq、organization、chatbot-file、contact、meeting-record

fieldName

string

是

欄位名稱,例如 file、logo、avatar、powered-by-logo、answer、compact_logo、audio

filename

string

是

檔案名稱,例如 example.pdf

fileSize

integer

是

檔案大小(bytes)

surface

object

否

上傳來自哪個產品,只用於上傳穩定度紀錄:webchat 帶 webchat;後台不帶 webchat: Web Chat;

請求結構範例

請求範例值

程式碼範例

回應內容

狀態碼: 200

回應結構範例

回應範例值


Presigned 上傳附件

POST /api/v1/attachments/

請求內容

請求參數

欄位
類型
必填
說明

type

object

否

filename

string

是

file

string (uri)

是

請求結構範例

請求範例值

程式碼範例

回應內容

狀態碼: 201

回應結構範例

回應範例值


取得特定附件

GET /api/v1/attachments/{id}/

參數

參數名稱
必填
類型
說明

id

✅

string

A UUID string identifying this attachment.

程式碼範例

回應內容

狀態碼: 200

回應結構範例

回應範例值


建立對話附件

POST /api/v1/conversations/{conversationPk}/attachments/

參數

參數名稱
必填
類型
說明

conversationPk

✅

string

請求內容

請求參數

欄位
類型
必填
說明

type

object

否

filename

string

是

file

string (uri)

是

conversation

string (uuid)

否

請求結構範例

請求範例值

程式碼範例

回應內容

狀態碼: 201

回應結構範例

回應範例值

狀態碼: 400 - Error codes (X-Error-Code): `conversation_attachment_limit_reached`, `conversation_attachment_storage_limit_reached`, `invalid`.

狀態碼: 404 - Error codes (X-Error-Code): `not_found`.

狀態碼: 429 - Error codes (X-Error-Code): `throttled`.


取得允許的檔案規格

GET /api/v1/allowed-file-specs/

程式碼範例

回應內容

狀態碼: 200

回應結構範例

回應範例值


列出對話附件

GET /api/v1/file-library/conversation-attachments/

所需權限:組織已開通檔案庫,且呼叫者的角色具備任一檔案庫權限。可見範圍與 expiresAt 的計算方式見技術手冊對話附件管理 API。

參數

參數名稱
必填
類型
說明

page

❌

integer

A page number within the paginated result set.

pageSize

❌

integer

Number of results to return per page.

程式碼範例

回應內容

狀態碼: 200

回應結構範例

回應範例值

狀態碼: 4XX - Error response; X-Error-Code carries its code (see "Error codes").


刪除對話附件

DELETE /api/v1/file-library/conversation-attachments/{id}/

所需權限:同「列出對話附件」;只能刪除呼叫者看得到的附件,其他附件回 404。刪除會一併移除沒有其他附件或檔案共用的儲存檔案。

參數

參數名稱
必填
類型
說明

id

✅

string

程式碼範例

回應內容

狀態碼
說明

204

No response body

4XX

Error response; X-Error-Code carries its code (see "Error codes").


最後更新於

這有幫助嗎?