当前位置: 首页>>代码示例>>Python>>正文


Python qiniu.Auth方法代码示例

本文整理汇总了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)


# 上传用户头像 
开发者ID:michwh,项目名称:onehome-server,代码行数:21,代码来源:views.py

示例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"] 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:25,代码来源:image_store.py

示例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 
开发者ID:glasslion,项目名称:django-qiniu-storage,代码行数:21,代码来源:clear_qiniu_bucket.py

示例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 
开发者ID:adisonhuang,项目名称:flask-blog,代码行数:18,代码来源:qiniustorage.py

示例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() 
开发者ID:billvsme,项目名称:videoSpider,代码行数:25,代码来源:upload_qiniu.py

示例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 
开发者ID:tuna,项目名称:fishroom,代码行数:13,代码来源:filestore.py

示例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')) 
开发者ID:kingname,项目名称:MarkdownPicPicker,代码行数:7,代码来源:QiniuUploader.py

示例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,
                    },
                },
            ) 
开发者ID:michwh,项目名称:onehome-server,代码行数:43,代码来源:consumers.py

示例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 
开发者ID:glasslion,项目名称:django-qiniu-storage,代码行数:15,代码来源:backends.py

示例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 
开发者ID:haizi-zh,项目名称:scrapy-qiniu,代码行数:10,代码来源:impl.py

示例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)) 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:5,代码来源:cdn.py

示例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 
开发者ID:gusibi,项目名称:momo,代码行数:7,代码来源:media.py

示例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) 
开发者ID:csuzhangxc,项目名称:Flask-QiniuStorage,代码行数:6,代码来源:flask_qiniustorage.py

示例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) 
开发者ID:csuzhangxc,项目名称:Flask-QiniuStorage,代码行数:6,代码来源:flask_qiniustorage.py

示例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) 
开发者ID:csuzhangxc,项目名称:Flask-QiniuStorage,代码行数:5,代码来源:flask_qiniustorage.py


注:本文中的qiniu.Auth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。