本文整理匯總了Python中sae.storage.Bucket.put_object方法的典型用法代碼示例。如果您正苦於以下問題:Python Bucket.put_object方法的具體用法?Python Bucket.put_object怎麽用?Python Bucket.put_object使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sae.storage.Bucket
的用法示例。
在下文中一共展示了Bucket.put_object方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: WriteZipFile
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def WriteZipFile(filename):
"""
保存所有kvdb數據,壓縮成zip然後aes cbc加密
"""
FileBuffer = io.BytesIO()
datalist = FindKVDBKeys()
if datalist:
zfile = zipfile.ZipFile(FileBuffer,mode='w')
for data in datalist:
# bytedata = (data + "tttttttt").encode(encoding="utf-8")
bytedata = kv.get(str(data))
if bytedata:
# print(bytedata)
zfile.writestr(str(data),bytedata)
zfile.close()
key = config.keyDataBackUp
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_ECB)
CryptIV = cipher.encrypt(iv)
cipher = AES.new(key, AES.MODE_CBC, iv)
bytebuffer = FileBuffer.getvalue()
lendata = 16 - len(bytebuffer)%16
bytebuffer = bytebuffer + chr(lendata)*lendata
#print(bytebuffer)
CryptData = CryptIV + cipher.encrypt(bytebuffer)
bucket = Bucket('backup')
# print(FileBuffer.getvalue())
bucket.put_object(filename,CryptData)
FileBuffer.close()
示例2: put_obj2storage
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def put_obj2storage(file_name="", data="", expires="365", type=None, encoding=None, domain_name=STORAGE_DOMAIN_NAME):
whichStorage = int(getAttr("DEFAULT_STORAGE"))
if whichStorage == 0:
bucket = Bucket(domain_name)
bucket.put_object(file_name, data, content_type=type, content_encoding=encoding)
return bucket.generate_url(file_name)
elif whichStorage == 1:
import qiniu.conf, qiniu.rs, qiniu.io
qiniu.conf.ACCESS_KEY = getAttr("QNKEY")
qiniu.conf.SECRET_KEY = getAttr("QNSECRET")
policy = qiniu.rs.PutPolicy(getAttr("QNSTORAGE"))
uptoken = policy.token()
key = file_name
if key[0] == "/":
key = key[1:]
ret, err = qiniu.io.put(uptoken, key, data)
if err is not None:
print "err = ", err
return ""
###下麵返回的網址有可能不同,有的是 xxxx.u.qiniudn.com 請改為自己的
return "http://%s/%s" % (getAttr("QNDOMAIN"), key)
else:
# 可後續擴展其他雲存儲
pass
return ""
示例3: initialize
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def initialize(*args):
global trie, FREQ, total, min_freq, initialized
if len(args)==0:
dictionary = DICTIONARY
else:
dictionary = args[0]
with DICT_LOCK:
if initialized:
return
if trie:
del trie
trie = None
t1 = time.time()
cache_file = 'jieba.cache'
default_dict = dictionary
default_bucket = getattr(settings, 'STORAGE_BUCKET_NAME')
bucket = Bucket(default_bucket)
cache_file_content = bucket.get_object_contents(dictionary)
dict_stamp = bucket.stat_object(default_dict)['timestamp']
load_from_cache_fail = True
try:
cache_stamp = bucket.stat_object(cache_file)['timestamp']
except:
cache_exists = False
else:
if cache_stamp > dict_stamp:
logger.debug("loading model from cache %s" % cache_file)
try:
cache_content = bucket.get_object_contents(cache_file)
trie,FREQ,total,min_freq = marshal.loads(cache_content)
load_from_cache_fail = False
except:
load_from_cache_fail = True
if load_from_cache_fail:
trie,FREQ,total = gen_trie(cache_file_content)
FREQ = dict([(k,log(float(v)/total)) for k,v in FREQ.iteritems()]) #normalize
min_freq = min(FREQ.itervalues())
logger.debug("dumping model to file cache %s" % cache_file)
try:
tmp_suffix = "."+str(random.random())
cache_file = 'dict' + tmp_suffix + '.cache'
cache_file = os.path.join(tempfile.gettempdir(), cache_file)
with open(cache_file,'wb') as temp_cache_file:
marshal.dump((trie,FREQ,total,min_freq),temp_cache_file)
if cache_exists:
bucket.delete_object('jieba.cache')
bucket.put_object('jieba.cache', open(cache_file, 'rb'))
except:
logger.error("dump cache file failed.")
logger.exception("")
initialized = True
logger.debug("loading model cost %s seconds." % (time.time() - t1))
logger.debug("Trie has been built succesfully.")
示例4: POST
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def POST(self):
context = web.input().context.encode('utf-8')
taskid = web.input().taskid
file_name = web.input().file_name
# Only segement the title and keyword
seg_content = []
lines = context.split('\r')
for line in lines:
tmp = line.split('\t')
seg_content.append(tmp[1])
seg_content.append(tmp[2])
results = get_seg_result('\t'.join(seg_content), keep_return=True)
newcontent = assemble_result(context, results['filtered_result'], taskid=taskid, file_name=file_name)
# log_message('Task ' + taskid + ' is excecuted (post), result: ' + '<br /> '.join(newcontent))
# submit to server
try:
# payload = urllib.urlencode([('seg_result', ''.join(newcontent).encode('utf-8')), ('taskid', taskid), ])
# req = urllib2.urlopen(SUBMIT_RESULT_URL, payload)
# log_message('submit task ' + str(taskid) + ' to server' + req.read())
from sae.storage import Bucket
bucket = Bucket('mozillaup')
bucket.put_object(file_name + '/' + str(taskid), ''.join(newcontent).encode('utf-8'))
# log_message('submit task ' + str(taskid) + ' to bucket')
except Exception, ex:
print ex
result = 'Encounter an error when submit task' + type(ex).__name__ + ' ' + str(ex.args)
log_message(result)
示例5: imgupload
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [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));
示例6: post
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def post(self, id):
id = int(id)
from sae.storage import Bucket
bucket = Bucket('audio')
fid = str(self.current_user) + datetime.now().strftime('/%Y-%m-%dT%H-%M-%S')
name = fid + '.wav'
#length = int(request.get_header('content-length',0))
bucket.put_object(name, self.request.body)
name = bucket.generate_url(name)
sss = Session()
model = RoomChat()
model.room_id = id
model.content_type = 'audio'
model.content = name
model.user_name = self.user.name
model.user_id = self.current_user
model.create_at = datetime.now()
sss.add(model)
sss.commit()
ls = GetTop.ajax(id)
self.render_list(*ls)
示例7: put_obj2storage
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [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
示例8: upload_file_handle
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [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
示例9: save_with_bucket
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def save_with_bucket(self, _bucket, fname, fcontent):
'''
_bucket is customer bucket name
'''
bk = Bucket(_bucket)
import StringIO
b = StringIO.StringIO(fcontent)
bk.put_object(fname, b.read())
return bk.generate_url(fname)
示例10: submit_report
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [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))
示例11: savePageAmazon
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def savePageAmazon(self, params):
url = self.amazonUrlBase + self.amazonUrlMap.get(params['category']) + self.amazonUrlTail + params['id']
page = self.getPage(url)
try:
conn = Connection(accesskey='ym51nzx10z', secretkey='h0kxmzj2ly13jjj1m0jjly41li1wimizzz2w2m32', retries=3)
spider = Bucket('amazon', conn)
spider.put_object(params['category'] + '/' + params['id'], page)
except Exception, e:
print e
示例12: save_img
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def save_img(uid,device_name,file1):
filename = file1.name
timestamp=filename.split(".")[0]
url="www.baidu.com"
if 'SERVER_SOFTWARE' in os.environ:
bucket = Bucket('domain2')
bucket.put_object(filename, file1)
url = bucket.generate_url(filename)
image=Img.create(uid=uid,timestamp=timestamp,device_name=device_name,url=url)
image.save()
示例13: edit0
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def edit0(request):
pname = pcomment = pmood = newname = 0
from sae.storage import Bucket
bucket = Bucket('abc')
if request.POST:
if request.POST.has_key('correct'):
if request.GET.has_key('atitle'):
pname = request.GET['atitle']
pn = t.objects.all()
if (len(pn)!= 0):
pname = pn[0].title
for i in pn:
i.delete()
we = imagess.objects.filter(title = pname)
if (len(we)!= 0):
img = bucket.get_object_contents('stati/'+pname)
im = Image.open(StringIO.StringIO(img))
imgout = StringIO.StringIO()
im.save(imgout,"jpeg")
img_data = imgout.getvalue()
we[0].title = request.POST['cname']+'.jpg'
newname = we[0].title
if (newname != pname):
ne = t(title = newname)
ne.save()
bucket.put_object('stati/'+newname, img_data)
im = Image.open(StringIO.StringIO(img))
out = im.resize((128, 128))
imgout = StringIO.StringIO()
out.save(imgout,"jpeg")
img_data = imgout.getvalue()
bucket.put_object('manage/'+newname, img_data)
bucket.delete_object('manage/'+pname)
bucket.delete_object('stati/'+pname)
pname = newname
we[0].comment = request.POST['ccomment']
we[0].mood = request.POST['cmood']
we[0].save()
pname = request.POST['cname']+'.jpg'
pcomment = request.POST['ccomment']
pmood = request.POST['cmood']
elif request.GET.has_key('atitle'):
if (pname == 0):
pname = request.GET['atitle']
p = t(title = pname)
p.save()
we = imagess.objects.filter(title = pname)
if (len(we)!= 0):
pcomment = we[0].comment
pmood = we[0].mood
if (pname!=0):
pname = pname[:-4]
return render_to_response('editt.html',{'pname':pname,'newname':newname, \
'pmood': pmood, 'pcomment':pcomment},context_instance=RequestContext(request))
示例14: upload_storage
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [as 別名]
def upload_storage(bucketname=BUCKET, savename="test.txt", filedata=None):
if bucketname and savename and filedata:
if DEBUG:
return None
from sae.storage import Bucket
bucket = Bucket(bucketname)
if savename[0]=="/":
savename = savename[1:]
bucket.put_object(savename, filedata)
return bucket.generate_url(savename)
else:
return False
示例15: thumbnail
# 需要導入模塊: from sae.storage import Bucket [as 別名]
# 或者: from sae.storage.Bucket import put_object [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()