I have a python server using the flask framework.
My application is a chatbot that talks to the user and performs some calculations in a dataset provided by the user.
I am already able to upload this data to the server, but when I try to use the data it is not loaded anymore. So I need to use this data until the user disconnect from my server.
Reading the Flask Documentation, I found some information that can lead me to what I need. The Application Context
Am I in the right direction?
This is how I am uploading the file in the server:
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
csv_input = pd.read_csv(stream,sep=None,engine='python')
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
session['receive_count'] = session.get('receive_count', 0) + 1
return render_template('index.html', async_mode=socketio.async_mode)
return render_template('index.html', async_mode=socketio.async_mode)