Exemplo n.º 1
0
def GetQiniuDlList(querySet=[],url='7xouyw.com1.z0.glb.clouddn.com',commonFlag=False):
    if len(querySet) <= 0:
        return querySet
    debug('func_yun.py->GetQiniuDlTokenList->querySet origin value:',querySet)
    #取所有_FILE_开头的字典名
    keys = []
    debug('func_yun.py->GetQiniuDlTokenList->querySet type:',isinstance(querySet[0],models.Model))

    keysall = []

    #未序列化的查询结果不处理
    if isinstance(querySet[0],models.Model):
        return querySet
    else:
        keysall = querySet[0].keys()


    for key in keysall:
        if isinstance(key,str):
            if key.startswith('_FILE_'):
                keys.append(key)

        else:
            pass

    debug('func_yun.py->GetQiniuDlTokenList->keys with file:',keys)

    if len(keys) <= 0:
        return querySet

    for i in range(0,len(querySet)):
        for key in keys:
            if querySet[i][key] is None or querySet[i][key] == '':
                querySet[i][key] = ''
                continue

            #文件列表
            fileList = querySet[i][key].split(',')
            for j in range(0,len(fileList)):

                #本来就是超链接直接返回
                if isSrc(key):
                    continue

                result,info = GetQiniuDlToken(fileList[j].split(globalvar.InterStr)[0],url,commonFlag)
                if result:
                    fileList[j] = info
                else:
                    fileList[j] = ''

            #拼接多媒体文件地址并赋值
            querySet[i][key] = ','.join(fileList)

    debug('func_yun.py->GetQiniuDlTokenList->querySet:',querySet)

    return querySet
Exemplo n.º 2
0
def DeleteFile(bucket_name,key):

    if isSrc(key):
        return

    #初始化Auth状态
    q = Auth(access_key, secret_key)

    #初始化BucketManager
    bucket = BucketManager(q)

    #你要测试的空间, 并且这个key在你空间中存在
    #bucket_name = 'Bucket_Name'
    #key = 'python-logo.png'

    #删除bucket_name 中的文件 key
    ret, info = bucket.delete(bucket_name, key)
    debug('func_yun->DeleteFile->info',info)
Exemplo n.º 3
0
def GetCommonUlToken(model='',count=1,fileType=''):

    q = Auth(access_key, secret_key)
    key = []
    token = []
    for i in range(0,count):
        
        #文件关键字名称,这个名称会定义到云上的名字
        
        key.append( model + get_random_string(16) + datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + '.' + fileType)
     
        try:
            token.append(q.upload_token(schoolBucketName, key[i], 7200, {CallBackName:URL,\
                CallBackTypeName:JsonType,CallBackBodyName:"{"+CallBackContentName+":$(key),hash:$(etag)}"}))
        except:
            debug( '第三方获取上传凭证函数异常')
            pass
    
    return token,key
Exemplo n.º 4
0
def GetQiniuDlToken(key,url='7xouyw.com1.z0.glb.clouddn.com',commonFlag=False):

    if key is '' or key is None:
        return False,'文件名为空'

    if isSrc(key):
        return True,key

    #公共空间,不需要生成下载凭证
    if commonFlag:
        return True,'http://%s/%s' % (url, key)

    #开发者账号授权
    q = Auth(access_key, secret_key)
    private_url = ''
    #生成私有的基本URL
    base_url = 'http://%s/%s' % (url, key)
    try:
        #生成私密url
        private_url = q.private_download_url(base_url, 3600)
        return True,private_url
    except:
        debug( '第三方获取上传凭证函数异常')
        return False,private_url