对象存储OBS-私有桶文件URL生成

已经过测试,直接上代码:

# -*- coding: UTF-8 -*-

# 引入模块
from obs import ObsClient
import sys
IS_PYTHON2 = sys.version_info.major == 2 or sys.version < '3'

if IS_PYTHON2:
    from urlparse import urlparse
    import httplib
else:
    import http.client as httplib
    from urllib.parse import urlparse

# 创建ObsClient实例
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***', 
    secret_access_key='*** Provide your Secret Key ***', 
    server='https://obs.cn-south-1.myhwclouds.com'
)

bucketName = '*** your bucketname ***''
objectKey = 'test.png'

res = obsClient.createSignedUrl('GET', bucketName, objectKey, expires=3600)
url = res['signedUrl']
print('Getting object using temporary signature url:')
print(res['signedUrl'])

# 关闭obsClient
obsClient.close()

使用自定义域名的情况

当需要使用自定义域名时,配server参数为自定义域名,然后在初始ObsClient的参数中增加参数“is_cname=True” 。

obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***', 
    secret_access_key='*** Provide your Secret Key ***', 
    server='***You own domain***',
    is_cname=True
)

参考:官方文档链接

你可能感兴趣的:(对象存储OBS-私有桶文件URL生成)