如何在烧瓶中使用自定义名称将图像保存在上传文件夹中?

How do I save an image in Upload Folder with a Custom name in flask?

我想用自定义名称保存此图像,以便我的 HTML 文件可以轻松显示该图像。我该怎么做?

import pathlib

def generate_custom_name(original_file_name):
    return "my_custom_file_name" + pathlib.Path(original_file_name).suffix
    
@app.route('/prediction', methods=['POST'])
def success():
    if request.method == 'POST':
        f = request.files['file']
        file_name = generate_custom_name(f.filename)
        f.save(os.path.join(UPLOAD_FOLDER, file_name))
        return "", 200