flask图片上传和下载

图片上传和显示

上传保存

def save_to_local(file, file_name):
        save_dir = app.config['UPLOAD_DIR']

        file.save(os.path.join(save_dir, file_name))

        return '/image/' + file_name

下载显示

@app.route('/image/')

def view_image(image_name):

        return send_from_directory(app.config['UPLOAD_DIR'], image_name)

 

你可能感兴趣的:(python)