本文整理汇总了Python中leancloud.File.save方法的典型用法代码示例。如果您正苦于以下问题:Python File.save方法的具体用法?Python File.save怎么用?Python File.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类leancloud.File
的用法示例。
在下文中一共展示了File.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_destroy
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
def test_destroy():
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.destroy()
示例2: test_destroy
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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()
示例3: test_thumbnail
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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')
示例4: test_thumbnail_size_erorr
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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)
示例5: test_thumbnail_size_erorr
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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)
示例6: test_thumbnail
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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')
示例7: get_img
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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
示例8: test_save
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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('.')
示例9: test_file_callback
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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)
示例10: upload_file
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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
示例11: test_fetch
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
def test_fetch():
r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png')
b = buffer(r.content)
f = File('Lenna2.jpg', b)
f.metadata['foo'] = 'bar'
f.save()
fetched = File.create_without_data(f.id)
fetched.fetch()
assert fetched.id == f.id
assert fetched.metadata == f.metadata
assert fetched.name == f.name
assert fetched.url == f.url
assert fetched.size == f.size
assert fetched.url == f.url
f.destroy()
示例12: upload
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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
示例13: test_fetch
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
def test_fetch(): # 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.metadata['foo'] = 'bar'
f.save()
fetched = File.create_without_data(f.id)
fetched.fetch()
normalized_f_url = f.url.split('/')[-1]
normalized_fetched_url = f.url.split('/')[-1]
assert fetched.id == f.id
assert fetched.metadata == f.metadata
assert fetched.name == f.name
assert fetched.size == f.size
assert fetched.url == f.url or normalized_fetched_url == normalized_f_url
f.destroy()
示例14: upload
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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
示例15: post
# 需要导入模块: from leancloud import File [as 别名]
# 或者: from leancloud.File import save [as 别名]
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