def post(self, *args, **kwargs): username = self.get_argument('username', '') nickname = self.get_argument('nickname', '') user_imgs = self.request.files.get('user_img', None) if username and nickname and user_imgs: if user_imgs: for user_img in user_imgs: img_save = ImageSave(self.settings['static_path'], user_img['filename']) user_img_url = img_save.save_userimg(user_img['body']) if self.current_user == username: self.orm.change_userinfo(username, nickname, user_img_url) self.redirect('/person')
def get(self, *args, **kwargs): resp = yield self.fetch_image() if not resp.body: self.write('empty data') return img_saver = ImageSave(self.settings['static_path'], 'x.jpg') img_saver.save_upload(resp.body) img_saver.make_thumb() username = self.get_argument('user', '') is_from_room = self.get_argument('from', '') == 'room' if username and is_from_room: self.orm.username = username post = self.orm.add_post_for_user(img_saver.upload_url, img_saver.thumb_url) print(f'-- {datetime.now()} -end fetch:#{post.id}') chat = make_chat(f'-----[{username}]-----', img_saver.thumb_url) chat['post_id'] = post.id chat['html'] = tornado.escape.to_basestring( self.render_string('message.html', message=chat)) ChatSocketHandler.update_cache(chat) ChatSocketHandler.send_updates(chat) else: self.write('user error')
def post(self, *args, **kwargs): img_files = self.request.files.get('newimg', None) post_id = 0 for img in img_files: img_saver = ImageSave(self.settings['static_path'], img['filename']) img_saver.save_upload(img['body']) img_saver.make_thumb() post = self.orm.add_post_for_user(img_saver.upload_url, img_saver.thumb_url) post_id = post.id self.redirect('/post/{}'.format(post_id))
def post(self, *args, **kwargs): img_files = self.request.files.get('newimg', None) # file_size = int(self.request.headers.get('Content-Length')) # if file_size / 1000.0 > 2000: # self.write('上传的图片不能超过2M') for img in img_files: image = ImageSave(self.settings['static_path'], img['filename']) image.save_upload(img['body']) #保存上次的图片 image.make_thumb() #生成缩略图 uploads(self.current_user, image.images_url, image.thumbs_url) #保存用户上传图片和缩略图的路径到数据库 self.write({'msg': 'got file: {}'.format(img_files[0]['filename'])}) self.redirect('/')
def get(self, *args, **kwargs): # python 3.6以后无法使用httpClient,同步使用requests # client = tornado.httpclient.HTTPClient() # resp = client.fetch(url) url = self.get_argument('url', '') resp = requests.get(url) img_saver = ImageSave(self.settings['static_path'], 'x.jpg') img_saver.save_upload(resp.content) img_saver.make_thumb() img = self.orm.add_img(self.current_user, img_saver.upload_url, img_saver.thumb_url) self.redirect('/post/{}'.format(img.id))
def get(self, *args, **kwargs): url = self.get_argument('url', '') client = tornado.httpclient.HTTPClient() try: resp = client.fetch(url) img_saver = ImageSave(self.settings['static_path'], 'x.jpg') img_saver.save_upload(resp.body) img_saver.make_thumb() post = add_post(self.current_user, img_saver.upload_url, img_saver.thumb_url) self.redirect('/post/{}'.format(post.id)) except tornado.httpclient.HTTPError as e: print("Error: " + str(e)) except Exception as e: print("Error: " + str(e)) client.close()
def post(self, *args, **kwargs): img_files = self.request.files.get("newimg", None) describe = self.get_argument('describe', None) img_id = 0 if img_files and describe: for img in img_files: img_save = ImageSave(self.settings['static_path'], img['filename']) img_save.save_upload(img['body']) img_save.make_thumb() upload_img = self.orm.add_img(img_save.upload_url, img_save.thumb_url, describe) img_id = upload_img.id self.redirect('/post/%s' % img_id) else: self.write("请选择图片!!!")
def get(self, *args, **kwargs): resp = yield self.fetch_image() if not resp.body: self.write('empty data') img_saver = ImageSave(self.settings['static_path'], 'x.jpg') img_saver.save_upload(resp.body) img_saver.make_thumb() user = self.get_argument('user', '') is_from_room = self.get_argument('from', '') == 'room' if user and is_from_room: img = add_img(user, img_saver.upload_url, img_saver.thumb_url) chat = make_chat( "{} post:http://39.108.160.235:8000/post/{}".format( user, img.id), img_saver.thumb_url) chat['html'] = tornado.escape.to_basestring( self.render_string('message.html', message=chat)) ChatSocketHandler.update_cache(chat) ChatSocketHandler.send_message(chat) else: self.write("No User")