def save_image_to_oss(file_, storge_path, key, when_fail=None):
if not allow_image_format(file_["filename"]):
raise gen.Return(invalid_argument_error('invalid image format: only jpg, ipeg, png is supported'))
if not allow_image_size(file_):
raise gen.Return(invalid_argument_error('invalid image size: less than or equal 2M is required'))
seed = hash_str(os.path.splitext(file_["filename"])[0] + key)
image_filename = storge_path + seed + os.path.splitext(file_["filename"])[1]
result = yield CommonTaskFactory. \
get_task(TaskNames.PROCESS_IMAGE.value). \
run('upload_file', file_["body"], image_filename)
if result:
raise gen.Return(image_filename)
else:
raise gen.Return(when_fail)
评论列表
文章目录