POST /api/v1/projects/{projectId}/storages
POST
/api/v1/projects/{projectId}/storages绑定存储(需 admin 及以上,API Key 不可用;需项目开通 allow_s3 权益)
请求参数
| 名称 | 类型 | 位置 | 必填 | 说明 |
|---|---|---|---|---|
projectId | string | path | 是 | 项目 ID(UUID)。携带 `X-API-Key` 时按 API Key scope 鉴权,否则按 JWT + 项目成员角色鉴权 |
请求体
请求数据
Content-Type · application/json
{
"type": "object",
"required": [
"name",
"provider",
"bucket",
"credentials"
],
"properties": {
"name": {
"type": "string"
},
"provider": {
"type": "string",
"enum": [
"oss",
"cos",
"s3"
]
},
"endpoint": {
"type": "string"
},
"bucket": {
"type": "string"
},
"region": {
"type": "string",
"description": "COS 需 region 或完整 endpoint"
},
"base_path": {
"type": "string"
},
"cdn_domain": {
"type": "string"
},
"credentials": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "oss: access_key/secret_key;cos: secret_id/secret_key;s3: access_key/secret_key"
}
}
}请求示例
cURL
curl -X POST 'http://localhost:8080/api/v1/projects/{projectId}/storages' \
-H 'Accept: application/json' \
-H 'X-API-Key: <PROJECT_API_KEY>'
# 也可使用登录会话:-H 'Authorization: Bearer <JWT>'JavaScript
const res = await fetch('http://localhost:8080/api/v1/projects/{projectId}/storages', {
method: 'POST',
headers: {
'Accept': 'application/json',
'X-API-Key': '<PROJECT_API_KEY>'
},
});
const data = await res.json();Python
import requests
res = requests.post(
'http://localhost:8080/api/v1/projects/{projectId}/storages',
headers={'Accept': 'application/json', 'X-API-Key': '<PROJECT_API_KEY>'}
)
print(res.json())响应
201创建成功(status=pending)
application/json
{
"type": "object",
"description": "存储配置(凭证不回显,仅以 has_credentials 标识)",
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"project_id": {
"type": "string",
"format": "uuid"
},
"name": {
"type": "string"
},
"provider": {
"type": "string",
"enum": [
"oss",
"cos",
"s3"
]
},
"endpoint": {
"type": "string"
},
"bucket": {
"type": "string"
},
"region": {
"type": "string"
},
"base_path": {
"type": "string"
},
"cdn_domain": {
"type": "string"
},
"status": {
"type": "string",
"enum": [
"pending",
"testing",
"active",
"failed",
"disabled"
]
},
"is_default": {
"type": "boolean"
},
"last_test_at": {
"type": "string",
"format": "date-time",
"nullable": true
},
"last_error": {
"type": "string"
},
"has_credentials": {
"type": "boolean"
},
"created_at": {
"type": "string",
"format": "date-time"
},
"updated_at": {
"type": "string",
"format": "date-time"
}
}
}400请求参数错误
application/json
{
"type": "object",
"properties": {
"code": {
"type": "string",
"example": "not_found"
},
"message": {
"type": "string",
"example": "资源不存在"
}
}
}403无权限(未通过 RBAC 或 2FA)
application/json
{
"type": "object",
"properties": {
"code": {
"type": "string",
"example": "not_found"
},
"message": {
"type": "string",
"example": "资源不存在"
}
}
}在线调试
在线调试
凭证仅保存在当前页面内存中自定义请求 Header
