本文整理汇总了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}
示例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}
示例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}