Skip to content

POST /api/v1/projects/{projectId}/uploads

POST/api/v1/projects/{projectId}/uploads

创建 Presigned 直传会话(需 developer 及以上;客户端直传对象存储,服务端不代理文件)

projectoperationId: projectUploadCreate

请求参数

名称类型位置必填说明
projectIdstringpath是项目 ID(UUID)。携带 `X-API-Key` 时按 API Key scope 鉴权,否则按 JWT + 项目成员角色鉴权

请求体

请求数据

Content-Type · application/json

{
  "type": "object",
  "required": [
    "filename",
    "content_type",
    "size"
  ],
  "properties": {
    "filename": {
      "type": "string"
    },
    "content_type": {
      "type": "string",
      "description": "长度不超过 255,须含 `/`"
    },
    "size": {
      "type": "integer",
      "format": "int64",
      "description": "大于 0 且不超过平台限制"
    }
  }
}

请求示例

cURL
curl -X POST 'http://localhost:8080/api/v1/projects/{projectId}/uploads' \
  -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}/uploads', {
  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}/uploads',
    headers={'Accept': 'application/json', 'X-API-Key': '<PROJECT_API_KEY>'}
)
print(res.json())

响应

201直传会话(默认 15 分钟有效)

application/json

{
  "type": "object",
  "properties": {
    "upload_id": {
      "type": "string",
      "format": "uuid"
    },
    "object_key": {
      "type": "string",
      "description": "以项目 slug 为前缀"
    },
    "upload_url": {
      "type": "string",
      "description": "客户端直传 URL"
    },
    "method": {
      "type": "string"
    },
    "headers": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "expires_at": {
      "type": "string",
      "format": "date-time"
    },
    "filename": {
      "type": "string"
    },
    "content_type": {
      "type": "string"
    },
    "size_bytes": {
      "type": "integer",
      "format": "int64"
    }
  }
}
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