Exemplo n.º 1
0
 def post(self, *args, **kwargs):
     img_files = self.request.files.get('newimg', None)  # 得到的是列表
     for img_file in img_files:
         saver = photo.ImageSave(self.settings['static_path'],
                                 img_file['filename'])
         saver.save_upload(img_file['body'])
         saver.make_thumb()
         add_post_for(self.current_user, saver.upload_url, saver.thumb_url)
         print("save to {}".format(saver.upload_path))
     self.redirect('/')
Exemplo n.º 2
0
    def post(self, *args, **kwargs):
        img_files = self.request.files.get('newing', None)
        for img in img_files:
            saver = photo.ImageSave(self.settings['static_path'],
                                    img['filename'])
            saver.save_upload(img['body'])
            saver.make_thumb()

            add_post_for(self.current_user, saver.upload_url, saver.thumb_url)
            print('save to {}'.format(saver.upload_path))

        self.render('upload.html')
Exemplo n.º 3
0
    def get(self, *args, **kwargs):
        url = self.get_argument('save_url', '')
        is_from_room = self.get_argument('from', '') == 'room'
        user = self.get_argument('user', '')
        if not (is_from_room and user):
            self.write('wrong call')
            return
        client = AsyncHTTPClient()

        resp = yield client.fetch(url)
        ims = UploadImageSave(self.settings['static_path'], 'x.jpg')
        ims.save_upload(resp.body)
        ims.make_thumb()

        post = add_post_for(user, ims.image_url, ims.thumb_url)
        chat = make_chat(
            '{} post new image:http://192.168.2.250:8080/post/{} '.format(
                user, post.id),
            img_url=post.thumb_url)
        # self.write(str(post.id))
        msg = {
            'html':
            tornado.escape.to_basestring(
                self.render_string(
                    'message.html',
                    message=chat,
                )),
            'id':
            chat['id'],
        }

        ChatSocketHandler.update_history(msg)
        ChatSocketHandler.send_updates(msg)
Exemplo n.º 4
0
    def post(self, *args, **kwargs):
        img_files = self.request.files.get('newing', None)
        for img in img_files:
            saver = photo.ImageSave(self.settings['static_path'],
                                    img['filename'])
            saver.save_upload(img['body'])
            saver.make_thumb()

            add_post_for(self.current_user, saver.upload_url, saver.thumb_url)
            print('save to {}'.format(saver.upload_path))
            self.redirect('/')

        self.render('upload.html')

        # self.write({'msg':'got file :{}'.format(img_files[0]['filename'])})
        self.write('恭喜您,完成提交!')
        self.redirect('explore')
Exemplo n.º 5
0
    def post(self, *args, **kwargs):
        # 保存上传的图片, 并压缩, 压缩图也保存
        global img_file
        img_files = self.request.files.get('newimg', None)
        for img_file in img_files:
            base_name = 'uploads/' + img_file['filename'] # 图片路径
            save_to = os.path.join(self.settings['static_path'], base_name) # 完整图片路径
            print("save to {}".format(save_to))
            with open(save_to, 'wb') as f:
                f.write(img_file['body'])
            full_path = photo.make_thumb(save_to) # 保存缩略图
            thumb_url = os.path.relpath(full_path, self.settings['static_path'])
            # 要拿到current_user此类必须继承 AuthBaseHandler即用户系统类
            add_post_for(self.current_user, base_name, thumb_url) # 把上传的图片路径保存到数据库

        self.write({'got file': img_file['filename']})
        self.redirect('/explore')
Exemplo n.º 6
0
    def get(self, *args, **kwargs):
        url = self.get_argument('save_url', '')

        resp = requests.get(url)
        ims = UploadImageSave(self.settings['static_path'], 'x.jpg')
        ims.save_upload(resp.content)
        ims.make_thumb()

        post = add_post_for(self.current_user, ims.image_url, ims.thumb_url)
        self.redirect('/post/{}'.format(post.id))
Exemplo n.º 7
0
    def post(self, *args, **kwargs):
        img_files = self.request.files.get('pic', None)
        if img_files:
            for img_file in img_files:
                image_url = 'uploads/' + img_file['filename']
                save_to = os.path.join(self.settings['static_path'], image_url)
                print("save to   {}".format(save_to))
                with open(save_to, 'wb') as f:
                    f.write(img_file['body'])
                photo.make_thumb(save_to)
                full_path = photo.make_thumb(save_to)
                thumb_url = os.path.relpath(full_path, self.settings['static_path'])
                account.add_post_for(self.current_user, image_url, thumb_url)

            self.write({'filename': img_files[0]['filename']})
            self.redirect('/explore')

        else:
            self.write({'msg':'empty form'})

        self.write({'msg': 'got file:{}'.format(img_files[0]['filename'])})
Exemplo n.º 8
0
    def post(self, *args, **kwargs):
        file_list = self.request.files.get('newimg', None)
        post_id = 0
        for upload in file_list:
            name = upload['filename']
            content = upload['body']
            # with open('static/uploads/{}'.format(name), 'wb') as f:
            #     f.write(content)
            imgsave = UploadImageSave(self.settings['static_path'], name)
            imgsave.save_upload(content)
            imgsave.make_thumb()

            post = add_post_for(self.current_user, imgsave.image_url,
                                imgsave.thumb_url)
            post_id = post.id

        self.redirect('/post/{}'.format(post_id))  #上传完成后跳转到图片详情页.