0

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?

Stephan
  • 3
  • 1

1 Answers1

0

Authenticity token is used to prevent CSRF attacks (more info here: Understanding the Rails Authenticity Token).
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.

Community
  • 1
  • 1
Faisal
  • 18,698
  • 4
  • 26
  • 32
  • 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 Oct 19 '10 at 13:31
  • I'm terribly sorry, but I have no idea. Try asking a separate question and tag it as a java applet Q. – Faisal Oct 19 '10 at 13:39
  • Thank, you were right about the sessions. I'm able to copy the page session by passing the session id as parameter. – Stephan Oct 19 '10 at 14:54