本文整理汇总了Python中sinastorage.bucket.SCSBucket.make_url方法的典型用法代码示例。如果您正苦于以下问题:Python SCSBucket.make_url方法的具体用法?Python SCSBucket.make_url怎么用?Python SCSBucket.make_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sinastorage.bucket.SCSBucket
的用法示例。
在下文中一共展示了SCSBucket.make_url方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: obj_upload
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import make_url [as 别名]
def obj_upload(data, fileTag):
""" Upload photo by object. """
sinastorage.setDefaultAppInfo(API_KEY, API_SECRET)
s = SCSBucket('sharephotos')
path = time.ctime().replace(' ', '_')
# if '/' in file name there will be problems
filename = fileTag[:6] + '_' + path + '.jpg' # use jpg temporary
scs_response = s.put(filename, data)
s.update_acl(filename, acl)
url = s.make_url(filename) # get url of image in the storage
return url
示例2: url_upload
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import make_url [as 别名]
def url_upload(imgSrc='http://www.w3school.com.cn/i/site_photoref.jpg'):
""" Upload photo by url. """
sinastorage.setDefaultAppInfo(API_KEY, API_SECRET)
s = SCSBucket('sharephotos')
data = urllib2.urlopen(imgSrc).read()
path = imgSrc.split('/')[2] + '/%s__' % time.ctime()
# if '/' in file name there will be problems
filename = path + imgSrc.replace('/', '_')
scs_response = s.put(filename, data)
s.update_acl(filename, acl)
url = s.make_url(filename) # get url of image in the storage
return url
示例3: test_make_url
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import make_url [as 别名]
def test_make_url(self):
scs = SCSBucket(self.bucket_name)
try:
scs.put_bucket('public-read-write')
except:
self.fail('create bucket:%s is failed'%self.bucket_name)
content = u'this is a file content text!!'
canned_acl = 'public-read' #快捷ACL
scs.put(key=self.object_key, data=content, acl=canned_acl)
url = scs.make_url(self.object_key)
#下载文件
# import urllib2
# response = urllib2.urlopen(url)
from sinastorage.compat import urllib
response = urllib.request.urlopen(url)
self.assertEqual(len(content), int(response.info()['Content-Length']), 'The response header Content-Length is not match')
示例4: storeImage
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import make_url [as 别名]
def storeImage(imgSrc):
sinastorage.setDefaultAppInfo("1cjfyo5kQPdnsI3cUc6W", "a3c139370a3509f269331930515729747573aa10")
djBucket = SCSBucket("dj-images") # not dj_images
acl = {} # Access control list
acl[ACL.ACL_GROUP_ANONYMOUSE] = [ACL.ACL_READ]
data = urllib2.urlopen(imgSrc).read()
path = imgSrc.split("/")[2] + "/"
# if '/' in file name there will be problems
filename = path + imgSrc.replace("/", "@")
scsResponse = djBucket.put(filename, data) # upload the file
stUrl = djBucket.make_url(filename) # get url of image in the storage
djBucket.update_acl(filename, acl) # set acl for the file
# save infomation to sql
try:
imgstorage.objects.get_or_create(original_url=imgSrc, storage_url=stUrl)
except:
print "insert into mysql error"
pass # solve this later
return stUrl
示例5: make_url
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import make_url [as 别名]
def make_url():
s = SCSBucket('test11')
return s.make_url('testpdf.pdf')