當前位置: 首頁>>代碼示例>>Python>>正文


Python Bucket.put方法代碼示例

本文整理匯總了Python中sae.storage.Bucket.put方法的典型用法代碼示例。如果您正苦於以下問題:Python Bucket.put方法的具體用法?Python Bucket.put怎麽用?Python Bucket.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sae.storage.Bucket的用法示例。


在下文中一共展示了Bucket.put方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: put_obj2storage

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [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
開發者ID:firsthym,項目名稱:rebang,代碼行數:33,代碼來源:views.py

示例2: imgupload

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [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));
開發者ID:HIT-MSTC,項目名稱:mstc-website,代碼行數:31,代碼來源:views.py

示例3: upload_file_handle

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [as 別名]
def upload_file_handle(f,user_id):
    from sae.storage import Bucket
    bucket=Bucket('image')
    bucket.put()
    file_postfix=f.name.split('.')[-1]
    file_name=str(user_id)+'.'+file_postfix
    bucket.put_object(file_name, f.read())
    return 'http://sumioo-image.stor.sinaapp.com/'+file_name
開發者ID:sumioo,項目名稱:demo,代碼行數:10,代碼來源:utils.py

示例4: submit_report

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [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'&lt;script\2&gt;'
				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))
開發者ID:yumendy,項目名稱:shsj,代碼行數:59,代碼來源:views.py

示例5: thumbnail

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [as 別名]
def thumbnail(request,filename):
    bucket = Bucket('upload')
    bucket.put()
    bucket.put_object("image/"+filename, request.FILES['file'])

    obj = bucket.get_object_contents("image/"+filename)
    image = Image.open(StringIO(obj))
    image.thumbnail((160,120),Image.ANTIALIAS)
    imgOut = StringIO()
    image.save(imgOut, 'jpeg')
    img_data = imgOut.getvalue()
    bucket.put_object('thumbnail/'+filename, img_data)
    imgOut.close()
開發者ID:heweiwei,項目名稱:Everyday,代碼行數:15,代碼來源:views.py

示例6: store_image

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [as 別名]
 def store_image(self):
     match = re.search(r'p[\d]+.jpg', self.douban.images)
     if match:
         image = urllib2.urlopen('http://img4.douban.com/view/photo/raw/public/' + match.group()).read()
     else:
         image = urllib2.urlopen(self.douban.images).read()
     from sae.storage import Bucket
     bucket = Bucket('infopic')
     bucket.put()
     filename = '%s.jpg' % self.id
     bucket.put_object(filename, image)
     url = bucket.generate_url(filename)
     self.images = url
     self.save()
開發者ID:akinoniku,項目名稱:episodeget,代碼行數:16,代碼來源:models.py

示例7: data_backup

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [as 別名]
def data_backup():
    """backup all data into sae storage

    """
    date = time.strftime("%Y_%m_%d")
    filename = 'mydata_' + date + '.json'
    kv = sae.kvdb.Client()
    myData = dict(kv.get_by_prefix(''))
    kv.disconnect_all()

    bucket = Bucket('t')
    bucket.put()
    myDataJson = json.dumps(myData)
    bucket.put_object(filename, myDataJson)
    return None
開發者ID:qingqingstudy,項目名稱:OMOOC2py,代碼行數:17,代碼來源:data.py

示例8: _upload_image

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [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]
開發者ID:merrycode,項目名稱:red,代碼行數:19,代碼來源:views.py

示例9: check_message

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [as 別名]
def check_message(message):
    kv = sae.kvdb.Client()
    if message == 'backup':
        bucket = Bucket('backup')
        bucket.put()
        data_dict = dict(kv.get_by_prefix(''))
        data_dict = json.dumps(data_dict)
        bucket.put_object('database.json', data_dict)
        return "備份成功!"
    elif message == 'ca':
        keys = kv.getkeys_by_prefix('')
        for key in keys:
            kv.delete(key)
        return "Database is empty!"
    elif '.' in message:
        funs, values = message.split('.',1)
        if funs == 'd':
            key = str(values)
            content = kv.get(key)
            kv.delete(key)
            return  "%s\n This item has beem deleted." %content
        elif funs == 'dp':
            prefix = values
            keys = kv.getkeys_by_prefix(prefix)
            for key in keys:
                kv.delete(key)
            return "%s\n All the keys' item have been deleted." %keys
        elif funs == 'get':
            prefix = str(values)
            content = dict(kv.get_by_prefix(prefix))
            return '''They are:
               %s
               '''% content
        elif funs == 'du':
            user_email = str(values)
            kv.delete(user_email)
            emails = kv.get('emailset')
            emails = [x for x in emails if not x == user_email]
            kv.set ('emailset',emails)
            number = kv.get('usersnumber') - 1
            kv.replace('usersnumber', number)
            return """用戶%s已經刪除"""%user_email
    else:
        return "Sorry, Please check your input..."
    kv.disconnect_all()
開發者ID:PythonNing,項目名稱:straypetshelper,代碼行數:47,代碼來源:pet.py

示例10: AvatarManager

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [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)
開發者ID:eavae,項目名稱:mlang,代碼行數:40,代碼來源:files.py

示例11: Blueprint

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [as 別名]
# coding=utf8

import datetime
import urllib
from flask import Blueprint, request, jsonify, render_template, g
import flask_login
from sae.storage import Bucket

from models.blog import create_session, BlogArticle
from utils.blog_cache import set_draft_blog
from configs import settings


bp_blog = Blueprint('blog', __name__, url_prefix='/blog')
bucket = Bucket(settings.STORAGE_BUCKET_DOMAIN_NAME)
bucket.put()


@bp_blog.route('/')
@bp_blog.route('/list/')
def list():
    session = create_session()
    blogs = session.query(BlogArticle).order_by(BlogArticle.update_time.desc())\
        .all()
    session.close()
    return render_template('blog/blog_list.html', blogs=blogs)


@bp_blog.route('/delete/<int:blog_id>/', methods=['POST'])
@flask_login.login_required
def delete(blog_id):
開發者ID:gausszh,項目名稱:sae_site,代碼行數:33,代碼來源:blog.py

示例12: report_edit

# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put [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'&lt;script\2&gt;'
						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))
開發者ID:yumendy,項目名稱:shsj,代碼行數:67,代碼來源:views.py


注:本文中的sae.storage.Bucket.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。