Search code examples
ruby-on-railsruby-on-rails-3paperclipswfuploadcsrf-protection

SwfUpload give 302 error when upload images


I am using swfUpload plugin with paperclip which use flash to upload images but when i press

upload button it give me this error and image are not upload and not save in DB.It show this error.

alexa's-lace-waist-yoga-pants-size4.jpg //this is my image for upload

Upload Error: 302 //this is error

any useful help will be most appreciated.

this is log output

Started POST "/admin/images/create_banner_image" for 202.154.225.30 at 2012-03-14 02:19:34 -0400 Processing by Admin::ImagesController#create_banner_image as HTML Parameters: {"Filename"=>"alexa's-lace-waist-yoga-pants-size4.jpg", "Filedata"=>#>, "Upload"=>"Submit Query"} WARNING: Can't verify CSRF token authenticity Completed 401 Unauthorized in 42ms

Now please answer @shinghara


Solution

  • If you want a quick hack, then adding

    protect_from_forgery :except => :create_banner_image
    

    to your Admin::ImagesController class should help.

    If you want to implement a secure solution - it'll require a bit more work. SWFupload uses flash, and it doesn't know anything about your Rails session unless you tell it. See good guide on how to fix it here: Rails 2.3.4 and SWFUpload – Rack Middleware for Flash Uploads that Degrade Gracefully