views:

40

answers:

2

I'm trying to use an Java Applet for uploading files to my rails application. However I keep getting the following error and I can't figure out why:

Processing CategoriesController#upload_image (for 127.0.0.1 at 2010-10-18 20:32:54) [POST] Parameters: {"partitionIndex"=>"0", "fileId"=>"8278320", "lastModified"=>"2010-09-18T14:31:12.610-0500", "fileLength"=>"18571", "fileName"=>"dreamstime_1038438.jpg.zip", "partitionCount"=>"1", "authenticity_token"=>"NHX938BYOQr/B4t1pb4pTMlgEFumfveXGxtROSChJpk=", "file"=>#}

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): :10:in synchronize' C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:111:inservice' C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:70:in run' C:/Ruby/lib/ruby/1.9.1/webrick/server.rb:183:inblock in start_thread'

I included the parameter authenticity_token as you can see above. The authenticity_token parameter is generated by form_authenticity_token(). In the same page there is a form and the authenticity_token is exactly the same. Any ideas what I'm overlooking here?

A: 

Try:

skip_before_filter :verify_authenticity_token

in your controller.

vic
I tried that too, but in that case I don't have my session variables. Which means that I can't verify if the user is logged in. The sessions are stored in the database, so I guess rails uses the token to find the session?
Stephan
A: 

Authenticity token is used to prevent CSRF attacks (more info here: http://stackoverflow.com/questions/941594/understand-rails-authenticity-token/1571900#1571900).
Maybe your applet is not maintaing its session? and each request is being sent as a separate session? This would cause the error you're facing to happen.

Faisal
Not maintaining the session could very well be the problem. How would an java applet join the same session as the page where it is included in?
Stephan
I'm terribly sorry, but I have no idea. Try asking a separate question and tag it as a java applet Q.
Faisal
Thank, you were right about the sessions. I'm able to copy the page session by passing the session id as parameter.
Stephan