七牛云存储 获取访问权限和存储区域的接口

发布于 2023-02-09  529 次阅读


在之前开发PicHoro和最近开发PicList的过程中,有一个困扰了我比较久的问题是官方文档中并没有找到能直接获取存储空间的访问权限和存储区域的接口,所以只能让用户去手动设置,十分的不方便。

分析七牛云的网页端的后台请求记录,发现其使用https://portal.qiniu.com/api/kodov2/uc/v2/bucketInfo?bucket=picli&fs=true来返回一个存储空间的详细信息,结合官方文档的其它API分析,推测通用的API地址是https://uc.qiniuapi.com,经过测试果然可行~

其中,返回数据内的private字段就对应了空间的访问权限,其中0代表公开,1代表私有;zoneregion字段对应了空间的存储区域。

POST 获取存储空间信息

POST /v2/bucketInfo
Host uc.qiniuapi.com

请求参数

名称 位置 类型 必选 说明
bucket query string 存储空间名
fs query string none
Authorization header string 管理凭证
Content-Type header string application/json
Host header string none

返回示例

成功

{
  "fragment_opt": {
    "fragment_size": 0,
    "ignore_etag_check": false
  },
  "protected": 0,
  "separator": "-",
  "transcode_styles": null,
  "styles": null,
  "refresh_time": 0,
  "refer_wl": null,
  "refer_bl": null,
  "no_refer": false,
  "source_enabled": false,
  "anti_leech_mode": 0,
  "private": 0,
  "no_index_page": 1,
  "cdn_auto_refresh": false,
  "cdn_auto_refresh_styled": false,
  "cdn_auto_refreshed_styles": null,
  "prefer_style_as_key": false,
  "max_age": 0,
  "gzip_close": false,
  "no_max_age": false,
  "mac_key": "",
  "mac_key2": "",
  "token_anti_leech": 0,
  "channel": null,
  "persist_fop": 0,
  "zone": "z0",
  "region": "z0",
  "global": false,
  "versioning": false,
  "encryption_enabled": false,
  "line": false,
  "type": 0,
  "notify_queue": "",
  "notify_message": "",
  "notify_message_type": "",
  "ouid": 0,
  "otbl": "",
  "oitbl": 0,
  "perm": 0,
  "share_users": null,
  "bucket_rules": null,
  "bucket_events": null,
  "fop_accs_wlist": null,
  "remark": "",
  "routing_rules": null,
  "file_num": 0,
  "storage_size": 0
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 Inline

返回数据结构

状态码 200