本文整理匯總了Python中sae.storage.Bucket.post方法的典型用法代碼示例。如果您正苦於以下問題:Python Bucket.post方法的具體用法?Python Bucket.post怎麽用?Python Bucket.post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sae.storage.Bucket
的用法示例。
在下文中一共展示了Bucket.post方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: put_obj2storage
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import post [as 別名]
def put_obj2storage(file_name = '', data = '', expires='365', type=None, encoding= None, domain_name = setting.STORAGE_DOMAIN_NAME):
import sae.const
access_key = sae.const.ACCESS_KEY
secret_key = sae.const.SECRET_KEY
appname = sae.const.APP_NAME
domain_name = "attachment"
bucket = Bucket(domain_name)
bucket.put()
bucket.post(metadata={'expires': '2d'})
attrs = bucket.stat()
bucket.put_object(file_name, data)
file_url = bucket.generate_url(file_name)
#begin to created
im = Image.open("/s/attachment/" + file_name)
#im = Image.open(bucket.get_object_contents(file_name))
im.thumbnail((320,200))
#im.save("/s/attachment/" + file_name+"_thumbnail.jpg")
imgext = re.search("(\.\w*)$", file_name)
if imgext:
thumbnail_name = file_name + "_thumbnail"+ imgext.group(1)
else:
thumbnail_name = file_name + "_thumbnail.jpg"
pureext = imgext.group(1)[1:]
if pureext == "jpg":
pureext = "jpeg"
#bucket.put_object(thumbnail_name, im.tostring('jpeg', 'RGB'))
bucket.put_object(thumbnail_name, im.tostring("jpeg", 'RGB'))
thumbnail_url = bucket.generate_url(thumbnail_name)
#s = sae.storage.Client()
#ob = sae.storage.Object(data = data, cache_control='access plus %s day' % expires, content_type= type, content_encoding= encoding)
return file_url, thumbnail_url
示例2: imgupload
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import post [as 別名]
def imgupload(req):
username = req.session.get("username",'')
if username == '':
return HttpResponseRedirect('/admin')
else:
if req.POST:
post = req.POST
if req.FILES:
img = req.FILES['img']
# s = Client()
bucket = Bucket('img')
# st = bucket.conn.__dict__
# if bucket.stat()['bytes'] == '0':
bucket.put()
bucket.post(acl='.r:.sinaapp.com,.r:sae.sina.com.cn')
tut = img._name.split('.')[-1]
dt_str = datetime.strftime(datetime.now(),'%Y%m%d%H%M%S')
filename = dt_str + str(randint(100,999)) + '.' + tut
bucket.put_object(filename,img)
# s.put('hitmstcweb',filename,img)
image = Img(
name = post.get('name','dt_str'), \
descripe = post.get('descripe',''), \
img = bucket.generate_url(filename), \
author = User.objects.get(username = username), \
)
image.save()
content = {'last_event':get_last_event()}
return render_to_response('imgupload.html',content,context_instance = RequestContext(req));
示例3: submit_report
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import post [as 別名]
def submit_report(req):
username = req.session.get('username','')
content = {'active_menu':'submitReport','num_need_check':num_need_check()}
status = ''
if username != '':
user = MyUser.objects.get(user__username = username)
content['user'] = user
else:
return HttpResponseRedirect('/login/')
if req.POST:
post = req.POST
if req.FILES:
img1 = req.FILES['img1']
img2 = req.FILES['img2']
bucket = Bucket('img')
bucket.put()
bucket.post(acl='.r:.sinaapp.com,.r:sae.sina.com.cn')
tut1 = img1._name.split('.')[-1]
tut2 = img2._name.split('.')[-1]
if tut1.lower() not in ['jpg','jpeg','bmp','gif','png']:
tut1 = 'jpg'
if tut2.lower() not in ['jpg','jpeg','bmp','gif','png']:
tut2 = 'jpg'
dt_str = datetime.datetime.strftime(datetime.datetime.now(),'%Y%m%d%H%M%S')
filename1 = dt_str + str(randint(100,999)) + '.' + tut1
filename2 = dt_str + str(randint(100,999)) + '.' + tut2
bucket.put_object(filename1,img1)
bucket.put_object(filename2,img2)
info = post.get('info','')
if len(info) < 500:
status = 'info_short'
else:
report = Report(
name = post.get('name',''),
start_time = post.get('start_time',''),
end_time = post.get('end_time',''),
address = post.get('address',''),
status = 1,
apply_time = 0,
apply_score = 0,
report_type = post.get('report_type',''),
author_type = post.get('author_type',''),
info_type = post.get('info_type',''),
author = user,
img1 = bucket.generate_url(filename1), \
img2 = bucket.generate_url(filename2), \
)
if post.get('info_type','') == '2':
a = re.compile(r'(<script)(.*)(>)',re.I)
res = r'<script\2>'
report.info = a.sub(res,info)
else:
report.info = info
report.save()
status = 'success'
content['status'] = status
return render_to_response('submitreport.html', content, context_instance = RequestContext(req))
示例4: _upload_image
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import post [as 別名]
def _upload_image(request, field="cover"):
if 'file' in request.FILES:
fobj = request.FILES['file']
content = fobj.read()
suffix = fobj.name.rsplit('.', 1)[1].lower()
if suffix not in ('jpg', 'png', 'jpeg'):
return _error(u'請上傳jpg或者png格式的照片')
md5 = hashlib.md5(content).hexdigest()
filename = '%s.%s' % (md5, suffix)
from sae.storage import Bucket
bucket = Bucket('adam')
bucket.put()
bucket.post(acl='.r:.sinaapp.com,.r:sae.sina.com.cn', metadata={'expires': '1y'})
bucket.put_object(filename, content)
return bucket.generate_url(filename)
return request.POST.get(field, '').strip()[0:255]
示例5: AvatarManager
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import post [as 別名]
class AvatarManager(object):
def __init__(self,app):
self.app = app
self.bucket = Bucket(app.config['STORAGE_NAME'])
self.bucket.put()
self.bucket.post(acl='.r:.sinaapp.com,.r:sae.sina.com.cn', metadata={'expires': '1d'})
def _saveAvatar(self,file,filename,size,sizecode):
filetype = file.mimetype.split('/')[1]
img = Image.open(StringIO(file.read()))
file.seek(0)
ratio = float(img.size[0]) / img.size[1]
if ratio > 1:
length = int(img.size[1]/2)
else:
length = int(img.size[0]/2)
x0,y0 = int(img.size[0]/2),int(img.size[1]/2)
img = img.crop((x0-length,y0-length,x0+length,y0+length))
img = img.resize((size,size),Image.ANTIALIAS)
output = StringIO()
img.save(output,filetype)
content = output.getvalue()
output.close()
self.bucket.put_object('avatar/'+filename, content, content_type=file.mimetype)
def saveAvatar(self,file,id):
filename = str(id)
self._saveAvatar(file,filename,self.app.config['AVATAR_SIZE_S'],'s')
self._saveAvatar(file,filename,self.app.config['AVATAR_SIZE_M'],'m')
self._saveAvatar(file,filename,self.app.config['AVATAR_SIZE_L'],'l')
def getAvatarUrl(self,id,sizecode):
try:
self.bucket.stat_object('avatar/'+str(id)+sizecode)
except :
return self.app.config['DEFAULT_AVATAR_URL']+'/'+sizecode
return self.bucket.generate_url('avatar/'+str(id)+sizecode)
示例6: report_edit
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import post [as 別名]
def report_edit(req):
username = req.session.get('username','')
status = ''
if username != '':
user = MyUser.objects.get(user__username = username)
else:
return HttpResponseRedirect('/login/')
Id = req.GET.get('id','')
try:
report = Report.objects.get(pk = Id)
except:
return HttpResponseRedirect('/reportlist/')
if report.author != user:
return HttpResponseRedirect('/reportlist/')
else:
if report.status != 1:
status = 'cannot_edit'
else:
if req.POST:
post = req.POST
if req.FILES:
img1 = req.FILES['img1']
img2 = req.FILES['img2']
bucket = Bucket('img')
bucket.put()
bucket.post(acl='.r:.sinaapp.com,.r:sae.sina.com.cn')
tut1 = img1._name.split('.')[-1]
tut2 = img2._name.split('.')[-1]
if tut1.lower() not in ['jpg','jpeg','bmp','gif','png']:
tut1 = 'jpg'
if tut2.lower() not in ['jpg','jpeg','bmp','gif','png']:
tut2 = 'jpg'
dt_str = datetime.datetime.strftime(datetime.datetime.now(),'%Y%m%d%H%M%S')
filename1 = dt_str + str(randint(100,999)) + '.' + tut1
filename2 = dt_str + str(randint(100,999)) + '.' + tut2
bucket.put_object(filename1,img1)
bucket.put_object(filename2,img2)
info = post.get('info','')
if len(info) < 500:
status = 'info_short'
else:
report.name = post.get('name','')
report.start_time = post.get('start_time','')
report.end_time = post.get('end_time','')
report.address = post.get('address','')
report.report_type = post.get('report_type','')
report.author_type = post.get('author_type','')
report.info_type = post.get('info_type','')
try:
img1 = bucket.generate_url(filename1)
img2 = bucket.generate_url(filename2)
report.img1 = img1
report.img2 = img2
except:
pass
if post.get('info_type','') == '2':
a = re.compile(r'(<script)(.*)(>)',re.I)
res = r'<script\2>'
report.info = a.sub(res,info)
else:
report.info = info
report.save()
status = 'success'
content = {'user':user,'active_menu':'submitReport','num_need_check':num_need_check(),'report':report, 'status':status}
return render_to_response("report_edit.html",content,context_instance = RequestContext(req))