Basis of rails driven photo website with a Flash uploader
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

41 lines
1.6 KiB

  1. # hacks for swfupload + cookie store to work
  2. # see http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
  3. #
  4. # also need to put
  5. # session :cookie_only => false, :only => :create
  6. # into the controller where the files are being uploaded (change method as appropriate)
  7. #
  8. # this goes in environment.rb
  9. class CGI::Session
  10. alias original_initialize initialize
  11. def initialize(request, option = {})
  12. session_key = option['session_key'] || '_session_id'
  13. query_string = if (qs = request.env_table["QUERY_STRING"]) and qs != ""
  14. qs
  15. elsif (ru = request.env_table["REQUEST_URI"][0..-1]).include?("?")
  16. ru[(ru.index("?") + 1)..-1]
  17. end
  18. if query_string and query_string.include?(session_key)
  19. option['session_data'] = CGI.unescape(query_string.scan(/#{session_key}=(.*?)(&.*?)*$/).flatten.first)
  20. end
  21. original_initialize(request, option)
  22. end
  23. end
  24. class CGI::Session::CookieStore
  25. alias original_initialize initialize
  26. def initialize(session, options = {})
  27. @session_data = options['session_data']
  28. original_initialize(session, options)
  29. end
  30. def read_cookie
  31. cookie = @session_data || @session.cgi.cookies[@cookie_options['name']].first
  32. return cookie if cookie
  33. return unless @session.cgi.request_method == "POST" # && @session.cgi.user_agent =~ /Flash Player/ This condition is commented, because of Flash user-agent differs a lot
  34. session_id = ActionController::CgiRequest.new(@session.cgi, ActionController::Base.session_options).request_parameters[@cookie_options['name']]
  35. return unless session_id
  36. @session.instance_variable_set('@session_id', session_id)
  37. end
  38. end