STORAGE_API.md 1.5 KB

文件存储 API 文档

本文档描述了文件上传相关的接口规范。

1. 全局响应结构

所有接口的返回值均由 GlobalResponseWrapper 统一包装,遵循以下 JSON 结构:

{
  "code": 200,          // 状态码 (200: 成功, 其他: 失败)
  "message": "success", // 响应消息
  "success": true,      // 成功标识
  "data": "https://...", // 具体业务数据 (文件URL)
  "timestamp": 1709628736123 // 响应时间戳
}

2. 上传文件到 Google Cloud Storage

  • URL: /google/upload/img
  • Method: POST
  • Content-Type: multipart/form-data
  • 描述: 上传文件到 Google Cloud Storage 存储桶,并返回可访问的 URL。

请求参数

字段名 类型 必填 说明
file file 是 需要上传的文件 (图片、视频等)
prefix string 是 文件存储路径前缀 (例如: avatar/, banner/),建议以 / 结尾

响应参数 (data 字段)

字段名 类型 说明
data string 文件访问的完整 URL

请求示例 (cURL)

curl --location --request POST 'http://localhost:8080/google/upload/img' \
--form 'file=@"/path/to/image.jpg"' \
--form 'prefix="test/"'

响应示例

{
  "code": 200,
  "message": "success",
  "success": true,
  "data": "https://storage.googleapis.com/aitori-public/test/a1b2c3d4e5f67890.jpg",
  "timestamp": 1709628736123
}