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:insynchronize'service’
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:111:in
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:70:inrun'block in start_thread’
C:/Ruby/lib/ruby/1.9.1/webrick/server.rb:183:in
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?
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.