Exemplo n.º 1
0
 def post(self, *args, **kwargs):
     try:
         # 获取入参
         image_metas = self.request.files['image']
     except:
         # 获取入参失败时,抛出错误码及错误信息
         logger.info("UploadFileHandle: request argument incorrect")
         http_params_error_response(self)
         return
     image_url = ""
     image_path_list = []
     if image_metas:
         # 获取当前的路径
         pwd = os.getcwd()
         save_image_path = os.path.join(pwd, "static/image/")
         logger.debug("UploadFileHandle: save image path: %s" % save_image_path)
         # 调用save_file方法将图片数据流保存在硬盘中
         file_name_list = save_files(image_metas, save_image_path)
         image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list]
         ret_data = {"imageUrl": image_path_list}
         # 返回图片下载地址给客户端
         http_simple_response(self, OK_CODE, "图片上传成功!", ret_data)
     else:
         # 如果图片为空,返回图片为空错误信息
         logger.info("UploadFileHandle: image stream is e...")
Exemplo n.º 2
0
    def post(self):
        try:
            # 获取入参
            image_metas = self.request.files['image']
        except:
            # 获取入参失败时,抛出错误码及错误信息
            logger.info("UploadFileHandle: request argument incorrect")
            http_error_response(self, -1)
            return

        image_url = ""
        image_path_list = []
        if image_metas:
            # 获取当前的路径
            pwd = os.getcwd()
            save_image_path = os.path.join(pwd, "static/image/")
            logger.debug("UploadFileHandle: save image path: %s" % save_image_path)
            # 调用save_file方法将图片数据流保存在硬盘中
            file_name_list = save_files(image_metas, save_image_path)
            image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list]
            ret_data = {"imageUrl": image_path_list}
            # 返回图片下载地址给客户端
            self.write(json.dumps({"data": {"msg": ret_data, "code": 0}}))
        else:
            # 如果图片为空,返回图片为空错误信息
            logger.info("UploadFileHandle: image stream is empty")
            http_error_response(self, -1)
Exemplo n.º 3
0
    def post(self):
        try:
            image_metas = self.request.files['image']
        except:
            log.info("UploadFileHandle: request argument incorrect!")
            http_response(self, ERROR_CODE['1001'], 1001)
            return

        image_url = ""
        image_path_list = []

        if image_metas:
            pwd = os.getcwd()
            save_image_path = os.path.join(pwd, SAVE_IMAGE_PATH)
            log.debug("UploadFileHandle: save image path:%s" %
                      (save_image_path))
            file_name_list = save_files(image_metas, save_image_path)
            image_path_list = [
                SERVER_HEADER + save_image_path + i for i in file_name_list
            ]
            ret_data = {"imageUrl": image_path_list}
            self.write(json.dumps({"data": {"msg": ret_data, "code": 0}}))
        else:
            log.info("UploadFileHandle: image stream is empty")
            http_response(self, ERROR_CODE['2001'], 2001)
Exemplo n.º 4
0
    def post(self):
        try:
            image_metas = self.request.files['image']
        except:
            http_response(self, ERROR_CODE['1001'], 1001)
            return

        # image_url = ""
        image_path_list = []
        if image_metas:
            # 获取当前的路径
            pwd = os.getcwd()
            save_image_path = os.path.join(pwd, "static/image/")
            file_name_list = save_files(image_metas, save_image_path)
            image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list]
            ret_data = {"imageUrl": image_path_list}
            self.write(json.dumps({"data": {"msg": ret_data, "code": 0}}))
        else:
            http_response(self, ERROR_CODE['2001'], 2001)
Exemplo n.º 5
0
 def post(self):
     if not self.get_current_user():
         http_error_simple_response(self, '请登录!')
         return
     try:
         book = {
             'bookId': self.get_argument('bookId'),
             'name': self.get_argument('name'),
             'isbn': self.get_argument('isbn'),
             'location': self.get_argument('location'),
             'publishingHouse': self.get_argument('publishingHouse'),
             'author': self.get_argument('author'),
             'coverUrl': self.get_argument('coverUrl'),
             'intro': self.get_argument('intro')
         }
     except:
         http_params_error_response(self)
         return
     try:
         # 获取入参
         image_metas = self.request.files['file']
     except:
         logger.info('获取图片出错!')
         image_metas = []
     if image_metas:
         # 存储图片
         pwd = os.getcwd()
         save_image_path = os.path.join(pwd, "static/image/")
         logger.debug("UploadFileHandle: save image path: %s" % save_image_path)
         # 调用save_file方法将图片数据流保存在硬盘中
         file_name_list = save_files(image_metas, save_image_path)
         image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list]
         book['coverUrl'] = image_path_list[0]
     result = update_book(book)
     print(result)
     if result[0]:
         http_simple_response(self, OK_CODE, '更新书籍信息成功!', result[1])
     else:
         http_error_simple_response(self, result[1])
     logger.debug("Search: update bookId="+book['bookId'])
Exemplo n.º 6
0
 def post(self, *args, **kwargs):
     if not self.get_current_user():
         http_error_simple_response(self, '请登录!')
         return
     try:
         book = {
             'name': self.get_argument('name'),
             'isbn': self.get_argument('isbn'),
             'location': self.get_argument('location'),
             'publishingHouse': self.get_argument('publishingHouse'),
             'author': self.get_argument('author'),
             'coverUrl': self.get_argument('coverUrl'),
             'intro': self.get_argument('intro'),
             'state': 0
         }
     except BaseException as e:
         http_error_simple_response(self, str(e))
         return
     try:
         # 获取入参
         image_metas = self.request.files['file']
     except:
         logger.info('获取图片出错!')
         image_metas = []
     if image_metas:
         # 存储图片
         pwd = os.getcwd()
         save_image_path = os.path.join(pwd, "static/image/")
         logger.debug("UploadFileHandle: save image path: %s" % save_image_path)
         # 调用save_file方法将图片数据流保存在硬盘中
         file_name_list = save_files(image_metas, save_image_path)
         image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list]
         book['coverUrl'] = image_path_list[0]
     result = add_book(book)
     http_simple_response(self, OK_CODE if result[0] else ERROR_CODE, result[1])
     logger.debug("Search: add book")
Exemplo n.º 7
0
    def post(self):
        try:
            #获取入参
            image_metas = self.request.files['image']
            token = self.request.headers['token']
        except:
            #获取入参失败时,抛出错误码及错误信息
            logger.info("UploadFileHandle: request argument incorrect")
            http_response(self, ERROR_CODE['1001'], 1001)
            return

        image_url = ""
        image_path_list = []
        if image_metas:
            #获取当前的路径
            pwd = os.getcwd()
            save_image_path = os.path.join(pwd, "static/image/")
            logger.debug("UploadFileHandle: save image path: %s" %
                         save_image_path)
            #调用save_file方法将图片数据流保存在硬盘中
            file_name_list = save_files(image_metas, save_image_path)
            image_path_list = [
                SERVER_HEADER + "/static/image/" + i for i in file_name_list
            ]
            #imageUrl存储到用户信息表中,需要改表结构,调用update方法
            self.db.query(Users).filter_by(token=token).update(
                {'avatarUrl': image_path_list})
            self.db.commit()
            self.db.close()
            ret_data = {"imageUrl": image_path_list}
            #返回图片下载地址给客户端
            http_response(self, "上传成功", 0, ret_data)
        else:
            #如果图片为空,返回图片为空错误信息
            logger.info("UploadFileHandle: image stream is empty")
            http_response(self, ERROR_CODE['2001'], 2001)