Home > Software engineering >  How do I save an image in Upload Folder with a Custom name in flask?
How do I save an image in Upload Folder with a Custom name in flask?

Time:05-18

saving image in upload folder

I want to save this image with a custom name so i can make my HTML file display that image easily. How can i do that?

CodePudding user response:

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
  • Related