anveo / swfupload_demo

How to use SWFUpload with custom Rack Middleware
http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/
67 stars 4 forks source link

ActionController::InvalidAuthenticityToken #1

Open mks0101 opened 15 years ago

mks0101 commented 15 years ago

Hi. anveo! I used your github swfupload_demo project in my project. but happened ActionController::InvalidAuthenticityToken.

So. why?

Now i spent to find ActionController::InvalidAuthenticityToken. help me.

my rails version 2.3.4 and using passenger-2.2.5.

my source below is...

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::Request.new(env).params env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil? end @app.call(env) end

end

require 'mime/types' class Fattachment < ActiveRecord::Base belongs_to :user has_attached_file :attachment, :url => "/fattachment/forums/:id/:style/:basename.:extension", :path => ":rails_root/public/fattachment/forums/:id/:style/:basename.:extension"

validates_attachment_presence :attachment
validates_attachment_size :attachment, :less_than => 1.megabytes
validates_attachment_content_type :attachment, :content_type => ['application/x-bittorrent', 'application/smil', 'text/plain', 'application/pdf', 'application/msword']

def swfupload_file=(data)
  data.content_type = MIME::Types.type_for(data.original_filename).to_s
  self.attachment = data
end

end

ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key])


<% session_key_name = ActionController::Base.session_options[:key] %>



---

Help me!
ghost commented 14 years ago

Hi, make sure that session data in additional post_params is set correctly!

I had to change this to the following:

post_params: {
'<%= ActionController::Base.session_options[:key] %>': '<%= cookies[ActionController::Base.session_options[:key]] %>',
'authenticity_token': '<%= form_authenticity_token %>'
},

I'm using Rails 2.3.5 and Passenger 2.2.7 – it works great with those settings above.