How to deal with the temporary storage of downloaded files

In my django application, I have multi-stage registration with several conditional parameters. Because of this, I decided to store data from forms in a session. Unfortunately, sessions serialize data using pickle, which does not support file serialization and reasons PicklingError: Can't pickle <type 'cStringIO.StringO'>: attribute lookup cStringIO.StringO failed. How to get around this problem? Should I send the image as a variable to all of the following views or send it as a GET parameter or do it in some other way? I'm not sure if any sample code is needed, as the problems seem pretty clear.

+3
source share
1 answer

If the files that are downloaded are larger than a few KB, then you probably do not want to store them in a session (and you definitely do not want to send them back to the browser via GET).

I can come up with several options:

  • You can rewrite your registration form to get the latest ones downloaded.
  • You can take your form one step and fake multi-step using javascript (e.g. hiding and displaying a DIV).
  • You can store temporary files on disk and store file names in a session (remembering to periodically clean up old files).
  • You can simplify your registration and upload the file on the "profile" page (it is possible to fulfill the requirement "you must fill out a profile" before allowing access to the rest of the site).
+1

Source: https://habr.com/ru/post/1764259/


All Articles