def post(self): if not self.current_user: raise tornado.web.HTTPError(401, "User not login") self.set_header('Access-Control-Allow-Origin', '*') self.set_header('Access-Control-Allow-Methods', 'POST, DELETE') if self.request.files["upload"][0]["content_type"] in [ "image/png", "image/jpeg" ]: fileName, fileExtension = os.path.splitext( self.request.files["upload"][0]["filename"]) fileMD5 = hashlib.md5( self.request.files["upload"][0]["body"]).hexdigest() with open("static/upload/" + fileMD5 + fileExtension, "w") as f: f.write(self.request.files["upload"][0]["body"]) f = StringIO.StringIO(self.request.files["upload"][0]["body"]) im = Image.open(f) im.resize((175, 175)).save("static/upload/" + fileMD5 + "_175x175" + fileExtension) im.resize((40, 40)).save("static/upload/" + fileMD5 + "_40x40" + fileExtension) profile_images = { "profile_img_40x40": "/static/upload/" + fileMD5 + "_40x40" + fileExtension, "profile_img_175x175": "/static/upload/" + fileMD5 + "_175x175" + fileExtension } nomagic.update_user(self.current_user["user_id"], profile_images) self.finish() return raise tornado.web.HTTPError(500, "Image file not support")
def post(self): if not self.current_user: raise tornado.web.HTTPError(401, "User not login") return self.set_header('Access-Control-Allow-Origin', '*') self.set_header('Access-Control-Allow-Methods', 'POST, DELETE') if self.request.files["upload"][0]["content_type"] in ["image/png", "image/jpeg"]: fileName, fileExtension = os.path.splitext(self.request.files["upload"][0]["filename"]) fileMD5 = hashlib.md5(self.request.files["upload"][0]["body"]).hexdigest() with open("static/upload/"+fileMD5+fileExtension, "w") as f: f.write(self.request.files["upload"][0]["body"]) f = StringIO.StringIO(self.request.files["upload"][0]["body"]) im = Image.open(f) im.resize((175, 175)).save("static/upload/"+fileMD5+"_175x175"+fileExtension) im.resize((40, 40)).save("static/upload/"+fileMD5+"_40x40"+fileExtension) profile_images = {"profile_img_40x40":"/static/upload/"+fileMD5+"_40x40"+fileExtension, "profile_img_175x175":"/static/upload/"+fileMD5+"_175x175"+fileExtension} nomagic.update_user(self.current_user["user_id"], profile_images) self.finish() return raise tornado.web.HTTPError(500, "Image file not support")
def post(self): if self.current_user: post_data = dict(zip(self.request.arguments.keys(), [i[0] for i in self.request.arguments.values()])) if(set(post_data.keys())-set(['name','title','department','mobile','about'])==set([])): #print post_data nomagic.update_user(self.current_user["user_id"], post_data) self.finish({"result":"success"}) return self.finish({"result":"error"})