Esempio n. 1
0
def cate_upload():
    """上传分类图标

    @@@
    #### args

    | args | nullable | type | remark |
    |--------|--------|--------|--------|
    |    file    |    false    |    File   |    上传的文件字段名    |

    #### return
    - ##### json
    > {"msg": "success", "code": 200}
    @@@
    """
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            new_filename = file_rename(file.filename, "cate")
            file.save(os.path.join(UPLOAD_FOLDER, new_filename))
            src = STATIC_URL + new_filename
        else:
            return jsonify({
                "status": 201,
                "msg": "error, please upload the correct type"
            })
        return jsonify({"status": 200, "msg": "上传成功", "src": src})
    else:
        return jsonify({"status": 202, "msg": "GET不支持"})
Esempio n. 2
0
def uploads():
    """上传诊断图片

    @@@
    #### args

    | args | nullable | type | remark |
    |--------|--------|--------|--------|
    |    file    |    false    |    File   |    上传的文件字段名    |
    |    user_id    |    false    |    Int   |    用户ID    |

    #### return
    - ##### json
    > {"msg": "success", "code": 200}
    @@@
    """
    if request.method == 'POST':
        file = request.files['file']
        user_id = request.form.get('user_id')
        if file and allowed_file(file.filename):
            new_filename = file_rename(file.filename, "upload")
            file.save(os.path.join(UPLOAD_FOLDER, new_filename))
            file_src = UPLOAD_FOLDER + new_filename
            user_pto_url = STATIC_URL + new_filename
            organs = faces(file_src)
            if organs["face"] is None:
                return jsonify({"status": 203, "msg": "请重新上传"})
            else:
                res = Userpto(user_id=user_id,
                              user_pto_url=user_pto_url,
                              face_pto_url=organs["face"],
                              left_eye_pto_url=organs["left_eye"],
                              right_eye_pto_url=organs["right_eye"],
                              nose_pto_url=organs["nose"],
                              tongue_pto_url=organs["tongue"])
                db.session.add(res)
                db.session.commit()
                return jsonify({"status": 200, "msg": "上传成功"})
        else:
            return jsonify({
                "status": 201,
                "msg": "error, please upload the correct type"
            })

    else:
        return jsonify({"status": 202, "msg": "GET不支持"})
Esempio n. 3
0
def save_face_file(file_src, types=None):
    new_pto_name = file_rename(types + ".jpg", types)
    pto_name = '{}/{}'.format(PROCESSED_URL, new_pto_name)
    cv.imwrite(pto_name, file_src)
    return new_pto_name