• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python qiniu.put_file函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qiniu.put_file函数的典型用法代码示例。如果您正苦于以下问题:Python put_file函数的具体用法?Python put_file怎么用?Python put_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了put_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: upload

 def upload(self, upload_dir, upload_bucket):
     if os.path.isdir(upload_dir):
         if os.path.isdir(upload_dir):
             up_file_list = []
             for root, dirs, files in os.walk(upload_dir,topdown=True):
                 for v_file in files:
                     up_file_list.append(os.path.join(root, v_file))
             for file_name in up_file_list:
                 token = self.mauth.upload_token(upload_bucket, file_name)
                 ret, info = put_file(token, file_name, file_name)
                 # print(info)
                 assert ret['key'] == file_name
                 assert ret['hash'] == etag(file_name)
                 print ret
         elif os.path.isfile(upload_dir):
             token = self.mauth.upload_token(upload_bucket, file_name)
             ret, info = put_file(token, file_name, file_name)
             assert ret['key'] == file_name
             assert ret['hash'] == etag(file_name)
             print ret
     elif os.path.isfile(upload_dir):
         file_name = upload_dir
         token = self.mauth.upload_token(upload_bucket, file_name)
         ret, info = put_file(token, file_name, file_name)
         assert ret['key'] == file_name
         assert ret['hash'] == etag(file_name)
         print ret
开发者ID:Arvon2014,项目名称:arvon-scripts,代码行数:27,代码来源:7niu_upload_mange.py


示例2: upload

def upload(key):
    access_key = 'Fx9CvaSHqUFVrofBgpGxAdsR3UV0SNB2bRof6ss2'
    secret_key = 'eW8fX00uUZukKcFsZyeIWw3BTyfhyoIhGQ4j5NwN'
    q = Auth(access_key, secret_key)
    bucket_name = 'bing'
    token = q.upload_token(bucket_name, key, 3600)
    localfile = key
    put_file(token, key, localfile)
开发者ID:merrygreek,项目名称:bing,代码行数:8,代码来源:bing.py


示例3: user_home

def user_home(request):
    user = get_user(request)

    if request.method == 'GET':
        data = {'user': user}

        return render(request, 'home/user/user_home.html', data)
    if request.method == 'POST':
        username = request.POST.get('username')
        icon = request.FILES['icon']
        email = request.POST.get('email')
        sex = request.POST.get('sex')
        tel = request.POST.get('tel')

        if username and username != user.username:
            if User.objects.filter(username=username).first():
                msg = '用户名已存在'
                return render(request, 'home/user/user_home.html', {'msg': msg})
            user.username = username

        if email and email != user.email:
            if User.objects.filter(email=email).first():
                msg = '该邮箱已注册'
                return render(request, 'home/user/user_home.html', {'msg': msg})
            if not re.match("^[a-zA-Z0-9_.-][email protected][a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$", str(email)):
                msg = '请输入有效邮箱号'
                return render(request, 'home/user/user_home.html', {'msg': msg})
            user.email = email

        if icon:
            with open(BASE_DIR + AVATAR_DIR, 'wb') as pic:
                for c in icon.chunks():
                    pic.write(c)
            # 构建鉴权对象
            q = qiniu.Auth(ACCESS_KEY, QINIU_SECRET_KEY)
            # 上传到七牛后保存的文件名
            key = 'static/icon/' + user.username + '/'+str(time.time())+'.jpg'
            # 生成上传 Token,可以指定过期时间等
            token = q.upload_token(BUCKET_NAME, key)
            localfile = BASE_DIR + '/static/images/icon.jpg'
            qiniu.put_file(token, key, localfile)
            user.icon = 'http://pbu0s2z3p.bkt.clouddn.com/' + key

        if tel and tel != user.tel:
            if User.objects.filter(tel=tel).first():
                msg = '该手机已注册'
                return render(request, 'home/user/user_home.html', {'msg': msg})
            if not re.match("^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$", str(tel)):
                msg = '请输入有效手机号'
                return render(request, 'home/user/user_home.html', {'msg': msg})
            user.tel = tel

        if sex and sex != user.sex:
            user.sex = 1 if sex == '男' else 0
        user.save()
        return HttpResponseRedirect('/user/user_home/')
开发者ID:SongJiaxin95,项目名称:GoodBuy,代码行数:56,代码来源:user_api.py


示例4: __upload_file

 def __upload_file(self,localphoto):
     localfile = localphoto.getpath()
     key = self.pre + localfile.split('\\')[-1]
     inf_key = key + '&&' + str(localphoto.getmood())\
               +'&&'+localphoto.getcomment()+'&&.inf'
     self.inf[key] = [localphoto.getmood(),localphoto.getcomment]
     token1 = self.q.upload_token(self.BN,inf_key)
     token = self.q.upload_token(self.BN, key)
     mime_type = self.__get_mime_type(localfile)
     params = {'x:a': 'a'}
     progress_handler = lambda progress, total: progress
     ret1, info1 = qiniu.put_file(token1, inf_key, self.static_file,params,\
                                mime_type, progress_handler=progress_handler)
     ret, info = qiniu.put_file(token, key, localfile, params,\
                                mime_type, progress_handler=progress_handler)
开发者ID:sunluchang,项目名称:xiaoyPhoto,代码行数:15,代码来源:WebConnection.py


示例5: to_upload_file

    def to_upload_file(self, f_file, f_md5, f_type):
        '''
            to upload file into qiniu bucket
        '''
        try:
            # f_name = os.path.basename(f_file)
            q = qiniu.Auth(self.access_key, self.secret_key)

            # key means filename in qiniu bucket
            key = "%s%s.%s" % (self.image_prefix, f_md5, f_type)
            token = q.upload_token(self.bucket_name, key)

            qiniu.put_file(token, key, f_file)
            return True
        except:
            return False
开发者ID:uyinn,项目名称:program_exercise,代码行数:16,代码来源:qiniu3.py


示例6: upload

def upload(args):
    """ Upload images to qiniu cloud
    """
    assert (args.bucket_name != None)
    assert (args.remote_dir != None)
    assert (args.input_file != None)
    assert (args.local_dir != None)

    bucket_name = args.bucket_name

    # with open(args.input_file) as fh:
    #     paths = filter(None, fh.readlines())
    img_num = 0
    for video in os.listdir(args.input_file):
        img_num += 1
        with open(os.path.join(args.input_file, video)) as fh:
            paths = filter(None, fh.readlines())
        mime_type = "image/jpg"

        for path in paths:
            key = (os.path.join(args.remote_dir, path)).strip('\n')
            print 'upload ', path, ' as ', key
            # path = path.split()[0]

            localfile = (os.path.join(args.local_dir, '%s' % (path))).strip('\n')
            print localfile
            token = q.upload_token(bucket_name, key)
            ret, info = put_file(token, key, localfile, mime_type=mime_type, check_crc=True)

            assert info.status_code == 200
            assert ret['key'] == key
            assert ret['hash'] == etag(localfile)

        print '%d images uploaded' % (img_num)
开发者ID:moushuai,项目名称:FlaskWebTool,代码行数:34,代码来源:tupu.py


示例7: upload_without_key

def upload_without_key(bucket, filePath, uploadname):
    '''上传文件'''
    auth = qiniu.Auth(accessKey, secretKey)
    upToken = auth.upload_token(bucket, key=None)
    key = uploadname
    retData, respInfo = qiniu.put_file(upToken, key, filePath, mime_type=mime.guess_type(filePath)[0])
    parseRet(retData, respInfo)
开发者ID:feimengspirit,项目名称:qiniu4blog,代码行数:7,代码来源:qiniu4blog.py


示例8: store_file

 def store_file(self, file_path, file_name):
     upload_token = self.credentials.upload_token(self.bucket_name, file_name)
     ret, err = put_file(upload_token, file_name, file_path)
     if ret is not None:
         return "%s/%s" % (self.imageServerUrl, ret['key'])
     else:
         logging.error('upload: %s error.' % file_name)
开发者ID:shigotonogo,项目名称:facehub,代码行数:7,代码来源:storage.py


示例9: upload_photo

def upload_photo():
    """上传照片到七牛,并返回私有链接地址"""
    from qiniu import Auth
    from qiniu import put_file

    global config
    progress_handler = lambda progress, total: progress

    photo_path = http_get("http://127.0.0.1:9876/photo/shot").content
    # Upload to qiniu
    mime_type = "image/jpeg"
    auth = Auth(str(config["qiniu"]["api_key"]), str(config["qiniu"]["secret"]))
    print auth
    filename = os.path.basename(photo_path)
    print "filename: ", filename, type(filename)
    token = auth.upload_token(str(config["qiniu"]["bucket"]))
    print token
    ret, info = put_file(token, filename, photo_path, {}, mime_type, progress_handler=progress_handler)
    print "uploaded: ", ret, info
    try:
        os.remove(photo_path)
    except Exception:
        pass

    # Return URL
    base_url = "{}/{}".format(str(config["qiniu"]["domain"]), filename)
    return auth.private_download_url(base_url, expires=3600)
开发者ID:JokerQyou,项目名称:bot,代码行数:27,代码来源:client.py


示例10: upload

def upload(origin_file_path):
    # 构建鉴权对象
    q = Auth(config.access_key, config.secret_key)

    # 要上传的空间
    bucket_name = 'md-doc'
    localfile = conwebp.convert(origin_file_path)

    # 上传到七牛后保存的文件名
    dest_prefix = time.strftime("%Y%m%d%H%M%S", time.localtime())
    dest_name = dest_prefix + "_" + os.path.basename(localfile)

    # 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器。
    policy = {
        'callbackBody': 'filename=$(fname)&filesize=$(fsize)'
    }

    token = q.upload_token(bucket_name, dest_name, 3600, policy)

    ret, info = put_file(token, dest_name, localfile)
    if ret is not None:
        print("Upload Success,url=", config.domin + dest_name)
    else:
        print("info=", info)
        print("ret=", ret)
    assert ret['key'] == dest_name
    assert ret['hash'] == etag(localfile)
开发者ID:Songziyuan,项目名称:QiniuUpload,代码行数:27,代码来源:qiniuUpload.py


示例11: loop_qiniu

def loop_qiniu():
    while True:
        for f in os.listdir(UPLOAD_FOLDER):
            if 'tmp' not in f.split('_')[-1]:
                os.remove(os.path.join(UPLOAD_FOLDER, f))
                # print 'jump out and for one more time'
            elif 'tmp0' == f.split('_')[-1]:
                continue
            elif 'tmp' == f.split('_')[-1]:
                print 'start handle %s' % f
                f_path = os.path.join(UPLOAD_FOLDER, f)
                f_path_new = os.path.join(UPLOAD_FOLDER, f[:-4])
                key = f[:-4]
                q = Auth(access_key, secret_key)
                token = q.upload_token(Bucket, key, 3600)
                local_file = f_path
                ret, _ = put_file(token, key, local_file)
                try:
                    assert ret['key'] == key
                except TypeError:
                    print 'ret has error'
                    continue
                os.rename(f_path, f_path_new)
                print 'end handle %s' % key
                print time.strftime("%Y/%y/%d %H:%M:%S", time.localtime(time.time()))
            else:
                print '<----'
                print u'为考虑到的情况'
                print time.strftime("%Y/%y/%d %H:%M:%S", time.localtime(time.time()))
                print '---->'
    print 'pass this time while error', time.strftime("%Y/%y/%d %H:%M:%S", time.localtime(time.time()))
开发者ID:shanyue-video,项目名称:one-night,代码行数:31,代码来源:loop.py


示例12: uploadToQiNiu

def uploadToQiNiu(filePath,name):
     q = Auth(access_key, secret_key)
     localfile = filePath
     key = name
     mime_type = "image/jpeg"
     token = q.upload_token(bucket_name, key)
     ret, info = put_file(token, key, localfile, mime_type=mime_type, check_crc=True)
开发者ID:HFS0921,项目名称:BingImage,代码行数:7,代码来源:bingT.py


示例13: upload_file

 def upload_file(self, bucket_name, key, file_path):
     #生成上传 Token,可以指定过期时间等
     token = self._q.upload_token(bucket_name, key, 3600)
     ret, info = put_file(token, key, file_path)
     print(info)
     pic_url = self.get_pic_url(bucket_name, file_path)
     add_to_clipboard(pic_url, file_path)
开发者ID:jimbray,项目名称:python_learning,代码行数:7,代码来源:get_content.py


示例14: test_upload

def test_upload():
    q = Auth(access_key, secret_key)
    token = q.upload_token(bucket, mykey.encode('utf-8'))
    file = '/tmp/abc.txt'
    ret, info = put_file(token, mykey.encode('utf-8'), file, mime_type="text/plain", check_crc=True)
    print(info)
    print(ret)
开发者ID:kongxx,项目名称:garbagecan,代码行数:7,代码来源:test.py


示例15: user_icon

def user_icon(request):
    if request.method == 'GET':
        return render(request, 'home/user/icon.html')
    if request.method == 'POST':
        file = request.FILES['avatar']
        with open(BASE_DIR+'/static/images/icon.jpg', 'wb') as pic:
            for c in file.chunks():
                pic.write(c)
        user = get_user(request)
        # 要上传的空间
        bucket_name = 'goodbuy'
        # 构建鉴权对象
        q = qiniu.Auth(ACCESS_KEY, QINIU_SECRET_KEY)
        # 上传到七牛后保存的文件名
        key = 'static/icon/'+user.username+'3.jpg'
        # 生成上传 Token,可以指定过期时间等
        token = q.upload_token(bucket_name, key)
        localfile = BASE_DIR+'/static/images/icon.jpg'
        ret, info = qiniu.put_file(token, key=key, file_path=localfile)
        print(info, ret)
        assert ret['key'] == key
        assert ret['hash'] == etag(localfile)
        user.icon = 'http://pbu0s2z3p.bkt.clouddn.com/'+key
        user.save()
        return JsonResponse({'key':key,'token':token})
开发者ID:SongJiaxin95,项目名称:GoodBuy,代码行数:25,代码来源:user_api.py


示例16: upload_img

def upload_img(bucket_name,file_name,file_path):
    # generate token
    token = q.upload_token(bucket_name, file_name, 3600)
    info = put_file(token, file_name, file_path)
    # delete local img file and if you do not want to delete local img,you just need to delete "os.remove(file_path)"
    os.remove(file_path)
    return
开发者ID:xhrwang,项目名称:MarkDownHelper,代码行数:7,代码来源:MarkDownHelper.py


示例17: qiniu_upload

def qiniu_upload(token, key, pic):
    #res = qiniu_token(file_name)
    ret, info  = put_file(token, key, pic)
    if  ret['key'] == key:
        return {"result" : True, "file_name" :  key}
    else:
        return {"result" : False, "file_name" :  ""}
开发者ID:liangxuCHEN,项目名称:CRM_systeme,代码行数:7,代码来源:tool.py


示例18: upload

def upload(filepath):
    qiniu_domain =  'http://7xtq0y.com1.z0.glb.clouddn.com/'
    #需要填写你的 Access Key 和 Secret Key
    access_key = 'NhxOewLDWpAs_THJNvtKN8kZHG3r0_tkWOaJSycc'
    secret_key = 'Cx7AJItEyNWaEG1eLvu85PpCGq0vAaX1xmvJC7c0'

    #构建鉴权对象
    q = Auth(access_key, secret_key)

    #要上传的空间
    bucket_name = 'images'

    #上传到七牛后保存的文件名
    key = os.path.basename(filepath)
    qiniu_url = qiniu_domain + key

    #生成上传 Token,可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)

    #要上传文件的本地路径
    localfile = filepath

    ret, info = put_file(token, key, localfile)
    print(info)
    print('===============')
    print(qiniu_url)

    return qiniu_url
开发者ID:zhengxiaowai,项目名称:face-recognition,代码行数:28,代码来源:upload.py


示例19: upload_file

def upload_file(localfile):
    # 需要填写你的 Access Key 和 Secret Key
    access_key = 'aRzVj18_VFA_p4EZ9z8ClWkVwYvAOWuoMStYnJhi'
    secret_key = 'bh_hBotfph77wcmHHIgCwExqKEvQN_eyT5m1r9_c'

    # 构建鉴权对象
    q = Auth(access_key, secret_key)

    # 要上传的空间
    bucket_name = 'myselfres'

    # 上传到七牛后保存的文件名

    key = time.strftime("%Y-%m-%d-%H-%M-%S.png", time.localtime())
    print key

    # 生成上传 Token,可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)

    # 要上传文件的本地路径

    ret, info = put_file(token, key, localfile)
    print (info)
    assert ret['key'] == key
    assert ret['hash'] == etag(localfile)

    pngOnlinePath = myselfres_dom + key + ')'
    setText(pngOnlinePath)
开发者ID:axidaka,项目名称:use-opensource,代码行数:28,代码来源:upload_file.py


示例20: upload

    def upload(self, pro_id, shop_id, img_type, f):
        if not pro_id or not shop_id or not img_type:
            return -1, '未传入userid或businesstype', (0,0)

        folder_path = os.path.join(self.folder, img_type)
        if not os.path.exists(folder_path):
            os.mkdir(folder_path)

        new_fname = self.gen_img_name(pro_id, img_type, f)
        new_fpath = os.path.join(folder_path, new_fname)

        im = Image.open(f)
        size = im.size
        if size[0] > 1000:
            w = size[0]
            h = size[1]
            size = (1000, int(h/w * 1000))

        nim = im.resize(size, Image.ANTIALIAS)
        nim.save(new_fpath, 'JPEG')
        size = nim.size

        token = self.get_token()
        ret, resp = put_file(token, new_fname, new_fpath, mime_type='image/jpeg', check_crc=True)
        if int(resp.status_code) == 614:
            print('已上传过,无需重复上传')
            return 614, '%s%s' % (self.url, new_fname), size
        elif int(resp.status_code) == 200:
            print("上传成功")
            return 200, '%s%s' % (self.url, new_fname), size
        else:
            print('访问出错,code:%s' % resp.status_code )
            return -1, resp.error, (0,0)
开发者ID:yangDL,项目名称:packsys,代码行数:33,代码来源:img_util.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python qiniu.Auth类代码示例发布时间:2022-05-26
下一篇:
Python qiniu.put_data函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap