views:

240

answers:

2

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.

A: 

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'])
jdwyah
I'd wanted to avoid going to the db for sessions, but given what this has turned into, I'm probably out of options. I'm not going to have a lot of users, so I'll just delete any session row in the DB that is older than an hour or so to keep DB size down. I'd still be interested in a method to forge the last link in the chain I've established, but for now I'm willing to experiment. A bit.
A: 

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/

DavidNorth