简体   繁体   中英

Can I force a rails session to reload from a string?

I have a third-party app (an upload progress bar - swfupload) that I'm using with rails 2.3.3 that cannot pass along session information or cookies. I can, however, pack the session data from my app into the URI it will use to upload a file and retrieve that when I get the file.

The trouble is, none of the magic hacks I see floating around the net work with 2.3.3. I don't know the specific details of why, but I've even tried the minimal RESTful demo application that uses swfupload and it pukes the same way mine does.

All I need is a way to force a reload of the session from a string, known to contain session data. Something along the lines of:

if session[:user_id]
  do stuff
else
  session.reload(session_string_from_uri)
end

You get the idea.

No, I'm not interested in trying yet another uploader solution for Rails. I've had enough of them fail that I'm going to stick with this solution because a simple answer to my current question will solve my problem.

Not sure if this is an option for you, but my swfuploader fix was easy because we have DB sessions.

_options['session_id'] = params[ _options['session_key'] ]   
session = Session.find_by_session_id(_options['session_id'])      

You need to use a rack middleware to restore the session from data posted along with the Flash request. Here is a very good article explaining this: http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM