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