附件與檔案
建立新附件 (整合)
POST /api/attachments-upload/
程式碼範例
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/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/attachments-upload/", formData, config)
.then(response => {
console.log('成功取得回應:');
console.log(response.data);
})
.catch(error => {
console.error('請求發生錯誤:');
console.error(error.response?.data || error.message);
});
import requests
url = "https://api.maiagent.ai/api/attachments-upload/"
headers = {
"Authorization": "Api-Key YOUR_API_KEY"
}
# 建立檔案和表單資料
files = {
'file': ('example_file.pdf', open('example_file.pdf', 'rb'), 'application/pdf')
}
response = requests.post(url, files=files, headers=headers)
try:
print("成功取得回應:")
print(response.json())
except Exception as e:
print("請求發生錯誤:", e)
<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
try {
$response = $client->post("https://api.maiagent.ai/api/attachments-upload/", [
'headers' => [
'Authorization' => 'Api-Key YOUR_API_KEY'
],
'multipart' => [
[
'name' => 'file',
'contents' => fopen('example_file.pdf', 'r'),
'filename' => 'example_file.pdf'
]
]
]);
$data = json_decode($response->getBody(), true);
echo "成功取得回應:\n";
print_r($data);
} catch (Exception $e) {
echo '請求發生錯誤: ' . $e->getMessage();
}
?>
回應內容
狀態碼
說明
200
No response body
取得檔案上傳用的預簽署 URL (建立/取得)
POST /api/upload-presigned-url/
參數
參數名稱
必填
類型
說明
fieldName
❌
string
欄位名稱
filename
❌
string
檔案名稱
modelName
❌
string
模型名稱
請求內容
請求參數
欄位
類型
必填
說明
fileSize
integer
是
請求結構範例
{
"fileSize": integer
}
請求範例值
{
"fileSize": 123
}
程式碼範例
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/upload-presigned-url/?fieldName=example&filename=example&modelName=example" \
-H "Authorization: Api-Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"modelName": "request_string",
"fieldName": "request_string",
"filename": "request_string",
"fileSize": 123
}'
# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
const axios = require('axios');
// 設定請求標頭
const config = {
headers: {
'Authorization': 'Api-Key YOUR_API_KEY',
'Content-Type': 'application/json'
}
};
// 請求內容 (payload)
const data = {
"modelName": "request_string",
"fieldName": "request_string",
"filename": "request_string",
"fileSize": 123
};
axios.post("https://api.maiagent.ai/api/upload-presigned-url/?fieldName=example&filename=example&modelName=example", data, config)
.then(response => {
console.log('成功取得回應:');
console.log(response.data);
})
.catch(error => {
console.error('請求發生錯誤:');
console.error(error.response?.data || error.message);
});
import requests
url = "https://api.maiagent.ai/api/upload-presigned-url/?fieldName=example&filename=example&modelName=example"
headers = {
"Authorization": "Api-Key YOUR_API_KEY",
"Content-Type": "application/json"
}
# 請求內容 (payload)
data = {
"modelName": "request_string",
"fieldName": "request_string",
"filename": "request_string",
"fileSize": 123
}
response = requests.post(url, json=data, headers=headers)
try:
print("成功取得回應:")
print(response.json())
except Exception as e:
print("請求發生錯誤:", e)
<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
try {
$response = $client->post("https://api.maiagent.ai/api/upload-presigned-url/?fieldName=example&filename=example&modelName=example", [
'headers' => [
'Authorization' => 'Api-Key YOUR_API_KEY',
'Content-Type' => 'application/json'
],
'json' => {
"modelName": "request_string",
"fieldName": "request_string",
"filename": "request_string",
"fileSize": 123
}
]);
$data = json_decode($response->getBody(), true);
echo "成功取得回應:\n";
print_r($data);
} catch (Exception $e) {
echo '請求發生錯誤: ' . $e->getMessage();
}
?>
回應內容
狀態碼: 200
回應結構範例
{
"url": string (uri) // S3 儲存桶的 URL
"fields": object // 用於 POST 請求的表單字段
}
回應範例值
{
"url": "https://s3.example.com/bucket-name",
"fields": {
"key": "media/chat/attachment/filename.pdf",
"x-amz-algorithm": "AWS4-HMAC-SHA256",
"x-amz-credential": "AKIAXXXXXXXXXXXXXXXX/YYYYMMDD/region/s3/aws4_request",
"x-amz-date": "YYYYMMDDTHHMMSSZ",
"policy": "base64-encoded-policy-document",
"x-amz-signature": "generated-signature-hash"
}
}
Presigned 上傳附件
POST /api/attachments/
請求內容
請求參數
欄位
類型
必填
說明
type
object
否
filename
string
是
file
string (uri)
是
請求結構範例
{
"type"?: object // 非必填
"filename": string
"file": string (uri)
}
請求範例值
{
"type": null,
"filename": "request_string",
"file": "request_string"
}
程式碼範例
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/attachments/" \
-H "Authorization: Api-Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": null,
"filename": "request_string",
"file": "request_string"
}'
# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
const axios = require('axios');
// 設定請求標頭
const config = {
headers: {
'Authorization': 'Api-Key YOUR_API_KEY',
'Content-Type': 'application/json'
}
};
// 請求內容 (payload)
const data = {
"type": null,
"filename": "request_string",
"file": "request_string"
};
axios.post("https://api.maiagent.ai/api/attachments/", data, config)
.then(response => {
console.log('成功取得回應:');
console.log(response.data);
})
.catch(error => {
console.error('請求發生錯誤:');
console.error(error.response?.data || error.message);
});
import requests
url = "https://api.maiagent.ai/api/attachments/"
headers = {
"Authorization": "Api-Key YOUR_API_KEY",
"Content-Type": "application/json"
}
# 請求內容 (payload)
data = {
"type": null,
"filename": "request_string",
"file": "request_string"
}
response = requests.post(url, json=data, headers=headers)
try:
print("成功取得回應:")
print(response.json())
except Exception as e:
print("請求發生錯誤:", e)
<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
try {
$response = $client->post("https://api.maiagent.ai/api/attachments/", [
'headers' => [
'Authorization' => 'Api-Key YOUR_API_KEY',
'Content-Type' => 'application/json'
],
'json' => {
"type": null,
"filename": "request_string",
"file": "request_string"
}
]);
$data = json_decode($response->getBody(), true);
echo "成功取得回應:\n";
print_r($data);
} catch (Exception $e) {
echo '請求發生錯誤: ' . $e->getMessage();
}
?>
回應內容
狀態碼: 201
回應結構範例
{
"id": string (uuid)
"type"?: object // 非必填
"filename": string
"file": string (uri)
}
回應範例值
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"type": {},
"filename": "response_string",
"file": "response_string"
}
建立對話附件
POST /api/conversations/{conversationPk}/attachments/
參數
參數名稱
必填
類型
說明
conversationPk
✅
string
請求內容
請求參數
欄位
類型
必填
說明
type
object
否
filename
string
是
file
string (uri)
是
conversation
string (uuid)
否
請求結構範例
{
"type"?: object // 非必填
"filename": string
"file": string (uri)
"conversation"?: string (uuid) // 非必填
}
請求範例值
{
"type": null,
"filename": "request_string",
"file": "request_string",
"conversation": "550e8400-e29b-41d4-a716-446655440000"
}
程式碼範例
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/conversations/{conversationPk}/attachments/" \
-H "Authorization: Api-Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": null,
"filename": "request_string",
"file": "request_string",
"conversation": "550e8400-e29b-41d4-a716-446655440000"
}'
# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
const axios = require('axios');
// 設定請求標頭
const config = {
headers: {
'Authorization': 'Api-Key YOUR_API_KEY',
'Content-Type': 'application/json'
}
};
// 請求內容 (payload)
const data = {
"type": null,
"filename": "request_string",
"file": "request_string",
"conversation": "550e8400-e29b-41d4-a716-446655440000"
};
axios.post("https://api.maiagent.ai/api/conversations/{conversationPk}/attachments/", data, config)
.then(response => {
console.log('成功取得回應:');
console.log(response.data);
})
.catch(error => {
console.error('請求發生錯誤:');
console.error(error.response?.data || error.message);
});
import requests
url = "https://api.maiagent.ai/api/conversations/{conversationPk}/attachments/"
headers = {
"Authorization": "Api-Key YOUR_API_KEY",
"Content-Type": "application/json"
}
# 請求內容 (payload)
data = {
"type": null,
"filename": "request_string",
"file": "request_string",
"conversation": "550e8400-e29b-41d4-a716-446655440000"
}
response = requests.post(url, json=data, headers=headers)
try:
print("成功取得回應:")
print(response.json())
except Exception as e:
print("請求發生錯誤:", e)
<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
try {
$response = $client->post("https://api.maiagent.ai/api/conversations/{conversationPk}/attachments/", [
'headers' => [
'Authorization' => 'Api-Key YOUR_API_KEY',
'Content-Type' => 'application/json'
],
'json' => {
"type": null,
"filename": "request_string",
"file": "request_string",
"conversation": "550e8400-e29b-41d4-a716-446655440000"
}
]);
$data = json_decode($response->getBody(), true);
echo "成功取得回應:\n";
print_r($data);
} catch (Exception $e) {
echo '請求發生錯誤: ' . $e->getMessage();
}
?>
回應內容
狀態碼: 201
回應結構範例
{
"id": string (uuid)
"type"?: object // 非必填
"filename": string
"file": string (uri)
"conversation"?: string (uuid) // 非必填
}
回應範例值
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"type": {},
"filename": "response_string",
"file": "response_string",
"conversation": "550e8400-e29b-41d4-a716-446655440000"
}
Last updated
Was this helpful?