天翼云对象存储使用方式包括api接口,天翼云对象存储Bucket标准访问权限解析及API接口使用指南
- 综合资讯
- 2025-03-29 18:24:37
- 4

天翼云对象存储支持API接口使用,提供Bucket标准访问权限解析及详细API接口使用指南,方便用户高效管理存储资源。...
天翼云对象存储支持API接口使用,提供Bucket标准访问权限解析及详细API接口使用指南,方便用户高效管理存储资源。
天翼云对象存储Bucket标准访问权限
天翼云对象存储的Bucket是存储对象的基本单元,每个Bucket可以设置不同的访问权限,天翼云对象存储的Bucket支持以下几种标准访问权限:
-
私有(Private):只有Bucket的创建者才能访问该Bucket中的对象。
-
公共读(Public Read):任何人都可以读取Bucket中的对象,但无法修改或删除。
图片来源于网络,如有侵权联系删除
-
公共读写(Public Read/Write):任何人都可以读取和修改Bucket中的对象。
-
匿名访问(Anonymous Access):允许所有用户通过匿名方式访问Bucket中的对象。
天翼云对象存储API接口
天翼云对象存储提供了丰富的API接口,方便用户进行数据存储、管理、访问等操作,以下是一些常用的API接口及其使用方法:
创建Bucket
创建Bucket是使用天翼云对象存储的第一步,以下为创建Bucket的API接口示例:
import requests url = "https://cos-api.cloud.189.cn/v5/objectstorage/v1/buckets" headers = { "Authorization": "Bearer access_token", "Content-Type": "application/json" } data = { "bucket": "example-bucket", "location": "example-location" } response = requests.post(url, headers=headers, json=data) print(response.json())
设置Bucket访问权限
设置Bucket访问权限可以通过API接口实现,以下为设置Bucket公共读权限的示例:
图片来源于网络,如有侵权联系删除
import requests url = "https://cos-api.cloud.189.cn/v5/objectstorage/v1/buckets/example-bucket/cors" headers = { "Authorization": "Bearer access_token", "Content-Type": "application/json" } data = { "corsRule": [ { "allowedHeaders": ["*"], "allowedMethods": ["GET", "PUT", "POST", "DELETE"], "allowedOrigins": ["*"], "ExposeHeaders": ["*"], "maxAgeSeconds": 3600 } ] } response = requests.put(url, headers=headers, json=data) print(response.json())
上传对象
上传对象到Bucket可以通过API接口实现,以下为上传对象的示例:
import requests url = "https://cos-api.cloud.189.cn/v5/objectstorage/v1/buckets/example-bucket/object" headers = { "Authorization": "Bearer access_token", "Content-Type": "application/octet-stream" } data = open("example-object", "rb") response = requests.put(url, headers=headers, data=data) print(response.json())
下载对象
下载对象可以通过API接口实现,以下为下载对象的示例:
import requests url = "https://cos-api.cloud.189.cn/v5/objectstorage/v1/buckets/example-bucket/object/example-object" headers = { "Authorization": "Bearer access_token" } response = requests.get(url, headers=headers) with open("downloaded-object", "wb") as f: f.write(response.content)
删除对象
删除对象可以通过API接口实现,以下为删除对象的示例:
import requests url = "https://cos-api.cloud.189.cn/v5/objectstorage/v1/buckets/example-bucket/object/example-object" headers = { "Authorization": "Bearer access_token" } response = requests.delete(url, headers=headers) print(response.json())
天翼云对象存储的Bucket支持多种标准访问权限,方便用户根据需求设置,天翼云对象存储提供了丰富的API接口,方便用户进行数据存储、管理、访问等操作,本文详细介绍了天翼云对象存储的Bucket标准访问权限和API接口使用方法,希望对您有所帮助。
本文链接:https://www.zhitaoyun.cn/1939643.html
发表评论