當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。