0

I am creating a web app in Flask that accepts an input dataset and an algorithm within an imported python script then manipulates it. The script generates and physically saves a .csv table ("zscore_data.csv") and a .png image ("zplot.png") which the user can then download. So essentially these are overwritten each time a new dataset is uploaded.

What if multiple users upload their datasets at the same time? Will user X accidentally download the files generated for user Y? (There are no user accounts associated with the users, the files are just stored in a downloads folder).

I am worried this will later cause problems. Any help would be appreciated!

To illustrate, in my script.py "zscore_data.csv" is saved to static/downloads:

zscore_csv = zscore_df.to_csv("static/downloads/zscore_data.csv", index=False)

In results.html a download link is provided:

<a href="{{ url_for('static', filename='downloads/zscore_data.csv') }}" class="link" download><strong>Z-Score Data (.csv)</strong></a>
vendrediSurMer
  • 398
  • 5
  • 15

1 Answers1

0

Yes this is definitely a valid concern. I've struggled with the same thing and it is not easy to deal with in a way that guarantees there will be no file leakage.

The ideal way to deal with this is if you can keep both as file objects until they are served by flask. I'm trying to find code for how I've done this before, but it was for a company that I don't work for anymore so i think the code is gone sadly.

Edit: It looks like you can just use Flask.send_file() and give it a file like object in place of the file path. The hard part for you might be rendering both the png and csv files to file objects as opposed to saving them to disk, given the libraries which you are creating them with.