当前位置: 首页>>代码示例>>Python>>正文


Python RequiredFeature.save方法代码示例

本文整理汇总了Python中hackathon.RequiredFeature.save方法的典型用法代码示例。如果您正苦于以下问题:Python RequiredFeature.save方法的具体用法?Python RequiredFeature.save怎么用?Python RequiredFeature.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hackathon.RequiredFeature的用法示例。


在下文中一共展示了RequiredFeature.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_files

# 需要导入模块: from hackathon import RequiredFeature [as 别名]
# 或者: from hackathon.RequiredFeature import save [as 别名]
    def upload_files(self):
        """Handle uploaded files from http request"""
        self.__validate_upload_files()

        images = []
        storage = RequiredFeature("storage")
        for file_name in request.files:
            file_storage = request.files[file_name]
            self.log.debug("upload image file : " + file_name)
            context = Context(
                hackathon_name=g.hackathon.name,
                file_name=file_storage.filename,
                file_type=FILE_TYPE.HACK_IMAGE,
                content=file_storage
            )
            context = storage.save(context)
            image = {
                "name": file_storage.filename,
                "url": context.url,
                "thumbnailUrl": context.url,
                "deleteUrl": '/api/admin/file?key=' + context.file_name
            }
            # context.file_name is a random name created by server, file.filename is the original name
            images.append(image)

        return {"files": images}
开发者ID:rapidhere,项目名称:open-hackathon,代码行数:28,代码来源:hackathon_manager.py

示例2: upload_files

# 需要导入模块: from hackathon import RequiredFeature [as 别名]
# 或者: from hackathon.RequiredFeature import save [as 别名]
    def upload_files(self, user_id, file_type):
        """Handle uploaded files from http request"""
        try:
            self.__validate_upload_files()
        except Exception as e:
            self.log.error(e)
            return bad_request("file size or file type unsupport")

        file_list = []
        storage = RequiredFeature("storage")
        for file in request.files:
            file_content = request.files[file]
            pre_file_name = file_content.filename
            file_suffix = pre_file_name[pre_file_name.rfind('.'):]
            new_file_name = self.__generate_file_name(user_id, file_type, file_suffix)
            self.log.debug("upload file: " + new_file_name)
            context = Context(
                file_name=new_file_name,
                file_type=file_type,
                content=file_content
            )
            context = storage.save(context)

            # file_name is a random name created by server, pre_file_name is the original name
            file_info = {
                "file_name": new_file_name,
                "pre_file_name": pre_file_name,
                "url": context.url
            }
            file_list.append(file_info)
        return {"files": file_list}
开发者ID:RangeForce,项目名称:open-hackathon,代码行数:33,代码来源:user_manager.py

示例3: upload_files

# 需要导入模块: from hackathon import RequiredFeature [as 别名]
# 或者: from hackathon.RequiredFeature import save [as 别名]
    def upload_files(self):
        status, return_info = self.validate_args()
        if not status:
            return return_info

        image_container_name = self.util.safe_get_config("storage.image_container", "images")
        images = []
        storage = RequiredFeature("storage")
        for file_name in request.files:
            file = request.files[file_name]
            self.log.debug("upload image file : " + file_name)
            context = Context(
                hackathon_name=g.hackathon.name,
                file_name=file.filename,
                file_type=FILE_TYPE.HACK_IMAGE,
                content=file
            )
            context = storage.save(context)
            image = {}
            image['name'] = file.filename
            image['url'] = context.url
            image['thumbnailUrl'] = context.url
            # context.file_name is a random name created by server, file.filename is the original name
            image['deleteUrl'] = '/api/admin/file?key=' + context.file_name
            images.append(image)

        # for file_name in request.files:
        # file = request.files[file_name]
        # real_name = self.generate_file_name(file)
        #     self.log.debug("upload image file : " + real_name)
        #
        #     url = self.file_service.upload_file_to_azure(file, image_container_name, real_name)
        #     if url is not None:
        #         image = {}
        #         image['name'] = file.filename
        #         image['url'] = url
        #         # frontUI components needed return values
        #         image['thumbnailUrl'] = url
        #         image['deleteUrl'] = '/api/file?key=' + real_name
        #         images.append(image)
        #     else:
        #         return internal_server_error("upload file failed")

        return {"files": images}
开发者ID:mshubian,项目名称:open-hackathon,代码行数:46,代码来源:hackathon_manager.py


注:本文中的hackathon.RequiredFeature.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。