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


Python leancloud.File类代码示例

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


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

示例1: test_destroy

def test_destroy():
    r = requests.get('http://www.lenna.org/full/len_std.jpg')
    b = buffer(r.content)
    f = File('Lenna2.jpg', b)
    f.save()
    assert f.id
    f.destroy()
开发者ID:heamon7,项目名称:python-sdk,代码行数:7,代码来源:test_file.py

示例2: test_destroy

def test_destroy():  # type: () -> None
    r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png')
    b = io.BytesIO(r.content)
    f = File('Lenna2.jpg', b)
    f.save()
    assert f.id
    f.destroy()
开发者ID:leancloud,项目名称:python-sdk,代码行数:7,代码来源:test_file.py

示例3: upload

def upload(file_path):
    print 'uploading file %s' % file_path
    img_name = path.split(file_path)[1]
    img_file = open(file_path)
    up_file = File(img_name, img_file)
    img_url = up_file.save().url
    return img_url
开发者ID:brucezz,项目名称:WriteMarkdownLazily,代码行数:7,代码来源:lzmd.py

示例4: test_thumbnail

def test_thumbnail():
    r = requests.get('http://www.lenna.org/full/len_std.jpg')
    f = File('Lenna2.jpg', r.content)
    f.save()
    assert f.id

    url = f.get_thumbnail_url(100, 100)
    assert url.endswith('?imageView/2/w/100/h/100/q/100/format/png')
开发者ID:gokure,项目名称:python-sdk,代码行数:8,代码来源:test_file.py

示例5: upload

def upload(file_path):
    cmp_file_path = dirpath + file_path
    if os.path.exists(cmp_file_path):
        img_name = os.path.split(cmp_file_path)[1]
        img_file = open(cmp_file_path)
        up_file = File(img_name, img_file)
        img_url = up_file.save().url
        # print(" url: %s" % img_url)
        return img_url
开发者ID:chocoluffy,项目名称:lazy-screen-capture,代码行数:9,代码来源:replaceClip.py

示例6: test_thumbnail

def test_thumbnail():
    r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png')
    b = buffer(r.content)
    f = File('Lenna2.jpg', b)
    f.save()
    assert f.id

    url = f.get_thumbnail_url(100, 100)
    assert url.endswith('?imageView/2/w/100/h/100/q/100/format/png')
开发者ID:lord63-forks,项目名称:python-sdk,代码行数:9,代码来源:test_file.py

示例7: get_img

def get_img(url):
    try:
        fn = url.split('/')[-1]
        c = urllib2.urlopen(url).read()
        f = StringIO(c)
        lc_file = File(fn, f)
        lc_file.save()
        r = lc_file.url
    except Exception, e:
        print '---------', e
        r = None
开发者ID:txdywy,项目名称:airbb,代码行数:11,代码来源:lc_img.py

示例8: test_save

def test_save():  # type: () -> None
    user = leancloud.User()
    user.login('user1_name', 'password')

    f = File('Blah.txt', open('tests/sample_text.txt', 'rb'))
    f.save()

    assert f.owner_id == user.id
    assert f.id
    assert f.name == 'Blah.txt'
    assert f.mime_type == 'text/plain'
    assert not f.url.endswith('.')
开发者ID:leancloud,项目名称:python-sdk,代码行数:12,代码来源:test_file.py

示例9: upload_file

 def upload_file(self, file_abspath):
     filename = os.path.basename(file_abspath)    # filename have suffix
     with open(file_abspath, 'r') as f:
         upload_file = File(filename, f)
         upload_file.save()
         print 'uploaded', file_abspath
         img_file = self._class()
         img_file.set('File', upload_file)
         img_file.set('filename', filename)
         tag_list = LeanCloudApi.get_tag_list(filename)
         img_file.set('tag_list', tag_list)
         img_file.save()
         self.add_img_info(img_file.id)    # save img_info after save
开发者ID:00nanhai,项目名称:picwall,代码行数:13,代码来源:leancloud_api.py

示例10: post

 def post(self, username):
     profile_fields = ['realName', 'gender', 'school', 'grade', 'major', 'about']
     userProfile = Query(UserProfile).equal_to("user", username).first()
     try:
         for key in profile_fields:
             userProfile.set(key, self.get_argument(key, ""))
             if 'file' in self.request.files:
                 file_dict_list = self.request.files['file']
                 for file_dict in file_dict_list:
                     data = file_dict["body"]
                     avatar = File("avatar", buffer(data))
                     avatar.save()
             userProfile.set("avatar", avatar.get_thumbnail_url(width='200', height='200'))
             userProfile.save()
             self.redirect('/user/'+username)
             print self.request
     except LeanCloudError, e:
         pass
开发者ID:LiuYiLe,项目名称:iclass,代码行数:18,代码来源:profile.py

示例11: test_thumbnail_size_erorr

def test_thumbnail_size_erorr():
    r = requests.get('http://www.lenna.org/full/len_std.jpg')
    f = File('Lenna2.jpg', r.content)
    f.save()
    assert f.id

    f.get_thumbnail_url(-1, -1)
    f.get_thumbnail_url(1, 1, quality=110)
开发者ID:gokure,项目名称:python-sdk,代码行数:8,代码来源:test_file.py

示例12: test_file_callback

def test_file_callback():  # type: () -> None
    d = {}

    def noop(token, *args, **kwargs):
        d['token'] = token

    f = File('xxx', io.BytesIO(b'xxx'))
    f._save_to_s3 = noop
    f._save_to_qiniu = noop
    f._save_to_qcloud = noop
    f.save()
    f._save_callback(d['token'], False)
开发者ID:leancloud,项目名称:python-sdk,代码行数:12,代码来源:test_file.py

示例13: test_thumbnail_size_erorr

def test_thumbnail_size_erorr():
    r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png')
    b = buffer(r.content)
    f = File('Lenna2.jpg', b)
    f.save()
    assert f.id

    f.get_thumbnail_url(-1, -1)
    f.get_thumbnail_url(1, 1, quality=110)
开发者ID:lord63-forks,项目名称:python-sdk,代码行数:9,代码来源:test_file.py

示例14: upload

def upload():
    if not session.get('session_token'):
        return redirect(url_for('accounts_bp.login'))

    app_id = session.get('app_id', None)
    developer = Developer()
    developer.session_token = session.get('session_token')
    username = developer.username()
    app_list = developer.get_app_list()

    if request.method == "POST":
        cert = request.files.get('cert')
        key = request.files.get('key')
        app_id = request.form.get('appId')
        passphrase = request.form.get('passphrase')
        if app_id not in map(lambda x: x['app_id'], app_list):
            flash("This appId owned by others", "alert")
            return redirect(url_for("settings.upload"))

        cert_pem = File(app_id + '_cert.pem', StringIO(cert.read()))
        key_pem = File(app_id + '_key.pem', StringIO(key.read()))
        cert_pem.metadata.update(owner=username)
        key_pem.metadata.update(owner=username)
        cert_url = cert_pem.save().url
        key_url = key_pem.save().url

        app_query = Query(Application)
        app_query.equal_to('objectId', app_id)
        app = app_query.first()

        if app:
            app.set('cert_url', cert_url)
            app.set('key_url', key_url)
            app.set('passphrase', passphrase)
            app.save()
        flash("Certificate has added done!")
        return redirect(url_for("settings.upload"))
    return render_template('settings/upload.html', username=username,
                           app_id=app_id, app_list=app_list)
开发者ID:mageia,项目名称:senz.dashboard.backend,代码行数:39,代码来源:settings.py

示例15: upload_image

def upload_image(fname):        
    HEIGHT, WIDTH = 384, 240
    #c = request.files['file'].read()
    with open(fname, 'rb') as f:
        c = f.read()
    file_orig = StringIO(c)
    im = Image.open(file_orig)
    h, w = im.size
    if h > HEIGHT or w > WIDTH:
        im.thumbnail((HEIGHT, WIDTH), Image.ANTIALIAS)
        file = StringIO()
        h, w = im.size
        if h==w:
            im = im.rotate(90 * 3)
        try:
            im.save(file, 'JPEG')
        except:
            #for .gif
            file = file_orig
    else:
        file = file_orig
    lc_file = File('pi', file_orig)
    lc_file.save()
    return lc_file.url 
开发者ID:txdywy,项目名称:flask,代码行数:24,代码来源:import_project.py


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