Uploadify, Flash Sessions, and Rails 2.3.8

I'm using Uploadify 2.1.4, and rails 2.3.8. I'm trying to apply the FlashSessionCookieMiddleware fix that is supposed to maintain session information during the uploadify's flash-based request. I've applied this fix after reading some of these guides:

  • Flash uploaders, Rails, cookie based sessions and CSRF: Rack Middleware to the rescue!
  • Uploadify on Rails with Paperclip

However, my session information is still not being carried over. Here's a look at my app configuration:

# config/environment.rb config.load_paths += %W( #{RAILS_ROOT}/config/middleware )

...

# config/middleware/flash_session_cookie_middleware.rb require 'rack/utils' class FlashSessionCookieMiddleware def initialize(app, session_key = '_session_id') @app = app @session_key = session_key end def call(env) if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/ params = ::Rack::Utils.parse_query(env['QUERY_STRING']) env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil? end @app.call(env) end end ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key])

...

// My Uploadify JS 'fileDataName' : 'file', 'queueID' : 'fileQueue', 'auto' : true, 'multi' : true, 'method' : 'get', 'scriptData' : { session_key: '<%= request.session_options[:key] %>'}

My middleware code is loading properly, Here's what rake middleware displays:

use Rack::Lock use ActionController::Failsafe use FlashSessionCookieMiddleware, "_my_app_session" use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActiveRecord::SessionStore, #<Proc:[email protected](eval):8> use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActionController::StringCoercion run ActionController::Dispatcher.new

Then, I try to test out if the last request has valid session/cookie info:

# In Controller logger.info "Session: #{session.inspect}"

Which prints only an empty hash in log/development.log:

Session: {}

[Sniff] Can anyone see what I'm doing wrong?

-------------Problems Reply------------

I was able to get this to work on 2.3.8 with steps as posted here : http://railstips.org/blog/archives/2009/07/21/uploadify-and-rails23/

Only thing I had to modify was flash_session_cookie_middleware.rb to the following:

require 'rack/utils'

class FlashSessionCookieMiddleware
def initialize(app, session_key = '_session_id')
@app = app
@session_key = session_key
end

def call(env)
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
@session_key = ActionController::Base.session_options[:key]
req = Rack::Request.new(env)
unless req.params[@session_key].nil?
env['HTTP_COOKIE'] = "#{@session_key}=#{req.params[@session_key]}".freeze
end
end

@app.call(env)
end
end

for those guys who want to solved the session problem by uploadify in Rails 3.0, please come here: http://www.damiangalarza.com/posts/ruby-on-rails/using-uploadify-with-rails-3/

Category:jquery Views:0 Time:2011-03-20

Related post

  • I/O Error with uploadify in ruby on rails 2012-01-09

    I'm trying to upload a image using uploadify and paperclip on rail 3.0.9 When i upload a image with uploadify, the server returns an I/O error. The development.log says: Started POST "/user/albums" for 127.0.0.1 at 2012-01-09 09:07:15 -0800 Processin

  • Implementing sessions in rails 2008-12-27

    I'm doing a first pass at rolling my own authentication and sessions in rails and am not sure that I understand the session support that is present. (By first pass, I mean I'm initially authenticating via http, not https. Production code will use htt

  • How to empty/destroy a session in rails? 2010-03-08

    I can't seem to find it anywhere... How do I delete/destroy/reset/empty/clear a user's session in Rails? Not just one value but the whole thing.. --------------Solutions------------- To clear the whole thing use the reset_session method in a controll

  • Things to consider while using session in Rails 2010-07-02

    While using session in Rails, what are the things that I have to be careful in perspective of security.? --------------Solutions------------- There is a good overview in this guide. There are vulnerabilities affect sessions regardless of what platfor

  • uploadify flash button not working in browser without flash in .net 2010-09-03

    I have written a multiple upload with uploadify jquery, but when I check it on a system with no flash player installed a blank area is present in the region of the uploadify flash button. How can I show the user a missing plug-in prompt, like in othe

  • How to show the flash message in Rails only once? 2011-02-28

    Is it possible to show the flash message in rails only once? I mean, when I delete something the flash says "Deleted (undo)", and then if I click a click and then the browser's Back button the message is still there. --------------Solutions----------

  • server error with uploadify in ruby on rails 3.1 2011-10-04

    I'm trying to upload a video using uploadify and paperclip on rail 3.1 When i upload a video with uploadify, the server returns an 500 error. The development.log says: Started POST "/videos" for 127.0.0.1 at Tue Oct 04 14:46:05 +0200 2011 Processing

  • What happened to the flash messages in Rails 3.2.1? 2012-03-06

    I use this code to display flash messages in Rails 3.2.1 apps (well, I did): <% flash.each do |name, msg| %> <div class="alert alert-<%= name == :notice ? "success" : "error" %>"> <%= msg %> </div> <% end %> But I

  • Can't understand sessions in Rails 2010-04-29

    Please don't bit my for my misunderstanding. The sessions are very new for me, and i have some problems. Okay i read many information about sessions and especially rails session. But this don't give me right imagine about sessions. Did i understand r

  • Inconsistent HTTP Errors from Uploading Images with Uploadify and Ruby on Rails 2010-07-17

    I'm having great difficulty in finding a bug preventing some uploads to my rails app through Uploadify. Here is the error I'm receiving: The thing that's making this difficult is that it's not at all consistent. Sometimes the images will upload perfe

  • How do I implement basic authentication with sessions in Rails? 2010-10-27

    Just learning Rails via Michael Hartl's tutorial and one of the things we have to do is implement basic authentication with sessions instead of cookies. I am trying to find any literature online that discusses it, but can't find anything. The Rails G

  • Selectively turning off Devise's flash notices in Rails 3 2011-03-12

    The Devise authentication framework uses flash notices everywhere. This makes it easy to integrate with apps but it leads to poor user experience sometimes. I am wondering what's an easy way to selectively turn off some of the Devise flash notices in

  • Is it possible to pass a flash message from Rails to Sinatra? 2011-03-15

    I have a project that uses Sinatra for static pages and Rails for the application. I allow the request to hit one or the other by doing this in config.ru: run Rack::Cascade.new([ EightyEightTactical::Root, EightyEightTactical::Application ]) Where Ei

  • Help debugging my session? Rails 3 ActionDispatch::Cookies::CookieOverflow 2011-04-30

    Even though I'm pretty sure I know why this error gets raised, I don't seem to know why or how my session is exceeding the 4KB limit... My app was working fine, but once I deliberately started adding bugs to see if my transactions were rolling back I

  • CookieOverflow with small session in rails 2011-07-29

    I'm having a problem with a rails application. I've searched google and stack overflow for some time now and couldn't find something similar to my specific case. The problem is CookieOverflow. Ok, there are a lot of topics on this subject, but all of

  • How to access session from Rails Integration Test? 2011-11-16

    Consider the following integration test: test "if there is no user in session, redirect to index and flash message" do open_session do |sess| post '/login', :email => users(:client).email, :password => 'rumpelstiltskin' sess[:user] = nil get '/

  • Create Session in Rails 3.1 Hartl Tutorial 2011-11-30

    This question is admittedly long. So I appreciate any support from the rubytutorial community. I am in Chapter 9, attempting to create a session for a logged-in user. I've done the tutorial already in < Rails 3.1. Since I am now using Rails 3.1, I

  • cakephp 2.x/uploadify: changing session id forces logout 2011-12-25

    I am messing with uploadify and cakephp (2.x) atm but I cant get it to work. It worked an hour ago and now it's magically destroyed. My cakephp application features a backend with a simple authentification. Users can upload images with uploadify and

  • How to I dynamically set the expiry time for a cookie-based session in Rails 2008-10-30

    I'm currently using the ActiveRecord-based session store for my Rails app and I have a background process which clears out inactive sessions every 30 minutes. I'd like to switch to Rails' new cookie-based session store but how do I set the expiry tim

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.205 (s). 11 q(s)