image_handler.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:xiaodi 作者: shenaishiren 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号