开发者

How to deal with temporary storage of uploaded files

开发者 https://www.devze.com 2023-01-15 22:49 出处:网络
In my django application I have a multi step registration, with few co开发者_高级运维nditional parameters. Because of this I figured out to store data from forms in session. Unfortunatelly sessions se

In my django application I have a multi step registration, with few co开发者_高级运维nditional parameters. Because of this I figured out to store data from forms in session. Unfortunatelly sessions serialize data using pickle, which doesn't support file serialization and causes

PicklingError: Can't pickle <type 'cStringIO.StringO'>: attribute lookup cStringIO.StringO failed . How to get around this problem ? Should I send image as a variable to all 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 since problems seems pretty clear.


If the files that are being uploaded are larger than a few KB in size, then you probably don't want to store them in the session (and you definitely don't want to send them back to the browser via a GET).

I can think of a few options:

  • You could rewrite your registration form so that uploaded files come last.
  • You can make your form a single step, and fake the multi-step with javascript (by hiding and showing DIV's, for example).
  • You could keep the temporary files on disk, and store the file names in the session (remembering to clean up old files periodically)
  • You could simplify your registration, and do the file upload on a "profile" page (perhaps enforcing a "you have to fill out the profile" requirement before allowing access to the rest of the site).
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号