本文整理汇总了Python中qiniu.Auth方法的典型用法代码示例。如果您正苦于以下问题:Python qiniu.Auth方法的具体用法?Python qiniu.Auth怎么用?Python qiniu.Auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiniu
的用法示例。
在下文中一共展示了qiniu.Auth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def post(self, request, format=None):
data = request.data
filetype = data.get('filetype')
# if request.user.is_authenticated:
# 构建鉴权对象
q = Auth(configs.get('qiniu').get('AK'), configs.get('qiniu').get('SK'))
# 生成图片名
salt = ''.join(random.sample(string.ascii_letters + string.digits, 8))
key = salt + '_' + str(int(time.time())) + '.' + filetype
# 生成上传 Token,可以指定过期时间等
token = q.upload_token(configs.get('qiniu').get('bucket_name'), key, 3600)
return Response({"stateCode": 200, "token": token, "key": key}, 200)
# else:
# return Response({"stateCode": 201, "msg": "您没有权限执行此操作"}, 201)
# 上传用户头像
示例2: storage
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def storage(data):
"""七牛云存储上传文件接口"""
if not data:
return None
try:
# 构建鉴权对象
q = Auth(access_key, secret_key)
# 生成上传 Token,可以指定过期时间等
token = q.upload_token(bucket_name)
# 上传文件,retult中包含一个key指的是上传文件的路径,info中存的是响应信息
ret, info = put_data(token, None, data)
except Exception as e:
logging.error(e)
raise e
if info and info.status_code != 200:
raise Exception("上传文件到七牛失败")
# 返回七牛中保存的图片名,这个图片名也是访问七牛获取图片的路径
return ret["key"]
示例3: main
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def main():
auth = Auth(QINIU_ACCESS_KEY, QINIU_SECRET_KEY)
bucket = BucketManager(auth)
while True:
ret, eof, info = bucket.list(QINIU_BUCKET_NAME, limit=100)
if ret is None:
print info
break
for item in ret['items']:
name = item['key']
print "Deleting %s ..." % name
ret, info = bucket.delete(QINIU_BUCKET_NAME, name)
if ret is None:
print info
if eof:
break
示例4: save_file
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def save_file(self, localfile, filename=None):
# 构建鉴权对象
auth = Auth(self._access_key, self._secret_key)
# 上传到七牛后保存的文件名
key = filename
# 生成上传 Token,可以指定过期时间等
token = auth.upload_token(self._bucket_name)
ret, info = put_file(token, key, localfile)
print(info)
try:
assert ret['key'] == key
assert ret['hash'] == etag(localfile)
except Exception as e:
current_app.logger.info(e)
return ret, info
示例5: upload_qiniu_by_filenames
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def upload_qiniu_by_filenames(access_key, secret_key, bucket_name, key_prefix,
pool_number, path, filenames, delete=False):
q = Auth(access_key, secret_key)
mime_type = "text/plain"
params = {'x:a': 'a'}
pool = Pool(pool_number)
for filename in filenames:
localfile = filename
key = os.path.join(key_prefix, localfile.replace(path, '')[1:])
token = q.upload_token(bucket_name, key)
pool.spawn(
down,
token=token,
key=key,
localfile=localfile,
mime_type=mime_type,
delete=delete
)
pool.join()
示例6: __init__
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def __init__(self, access_key, secret_key, bucket_name, counter, base_url):
try:
import qiniu
except ImportError:
raise Exception("qiniu sdk is not installed")
self.qiniu = qiniu
self.auth = qiniu.Auth(access_key, secret_key)
self.bucket = bucket_name
self.counter = counter
self.base_url = base_url
示例7: __init__
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def __init__(self, config_info):
self.upload_handler = None
self.url = config_info['url']
self.container_name = config_info.get('container_name')
self.upload_handler = Auth(config_info.get('access_key'), config_info.get('secret_key'))
示例8: receive_json
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def receive_json(self, message, **kwargs):
# 收到信息时调用
to_user = message.get('to_user')
from_user = message.get('from_user')
time = message.get('time')
# 信息发送
length = len(ChatConsumer.chats[self.group_name])
if length == 2:
# print('两个人')
await self.channel_layer.group_send(
self.group_name,
{
"type": "chat.message",
"message": message.get('message'),
"from_user": from_user,
"to_user": to_user,
"time": time,
},
)
else:
try:
user = User.objects.get(id__exact=from_user)
except User.DoesNotExist:
user = None
q = Auth(configs.get('qiniu').get('AK'), configs.get('qiniu').get('SK'))
avatar_url = q.private_download_url(user.user_image_url, expires=3600)
from_username = user.username
await self.channel_layer.group_send(
to_user,
{
"type": "push.message",
"event": {
'message': message.get('message'),
'group': self.group_name,
'from_user': from_user,
'time': time,
'avatar_url': avatar_url,
'from_username': from_username,
},
},
)
示例9: __init__
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def __init__(
self,
access_key=QINIU_ACCESS_KEY,
secret_key=QINIU_SECRET_KEY,
bucket_name=QINIU_BUCKET_NAME,
bucket_domain=QINIU_BUCKET_DOMAIN,
secure_url=QINIU_SECURE_URL):
self.auth = Auth(access_key, secret_key)
self.bucket_name = bucket_name
self.bucket_domain = bucket_domain
self.bucket_manager = BucketManager(self.auth)
self.secure_url = secure_url
示例10: get_bucket_mgr
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def get_bucket_mgr(self):
if not self._bucket_mgr:
ak = self.access_key
sk = self.secret_key
q = Auth(ak, sk)
self._bucket_mgr = BucketManager(q)
return self._bucket_mgr
示例11: __init__
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def __init__(self):
self.manager = CdnManager(Auth(access_key=settings.QINIU_ACCESSKEY,
secret_key=settings.QINIU_ACCESSSECRET))
示例12: qiniu_auth
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def qiniu_auth():
access_key = str(Config.QINIU_ACCESS_TOKEN)
secret_key = str(Config.QINIU_SECRET_TOKEN)
auth = Auth(access_key, secret_key)
return auth
示例13: save
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def save(self, data, filename=None):
auth = QiniuClass.Auth(self._access_key, self._secret_key)
token = auth.upload_token(self._bucket_name)
return QiniuClass.put_data(token, filename, data)
示例14: delete
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def delete(self, filename):
auth = QiniuClass.Auth(self._access_key, self._secret_key)
bucket = QiniuClass.BucketManager(auth)
return bucket.delete(self._bucket_name, filename)
示例15: private_url
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import Auth [as 别名]
def private_url(self, filename):
auth = QiniuClass.Auth(self._access_key, self._secret_key)
return auth.private_download_url(urljoin(self._base_url, filename), expires=3600)