reham501
reham501

Reputation: 159

how to temporary store uploaded files using FLASK

I'm creating a web application using flask that takes 3 input from the user: name, picture, grades.

I want to store these information temporary depending on the user's session. and as a beginner I read that sessions are not for storing files, what other secure way you recommend me to use?

Upvotes: 0

Views: 3112

Answers (1)

Jürgen Gmach
Jürgen Gmach

Reputation: 6121

I would recommend to write the files to disk.

If this is really temporary, e.g. you have a two-step-sign-up-form, you could write the files to temporary files or into a temporary directory.

Please see the excellent documentation at https://docs.python.org/3/library/tempfile.html

Maybe this should not be this temporary? It sounds like a user picture is something more permanent.

Then I would recommend e.g. to create a directory for each user and store the files there.

This is done with standard Python io, e.g with the open function.

More info about reading and writing files also can be found in the official Python documentation:

https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

Upvotes: 1

Related Questions