<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: session code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 18:47:34 GMT</pubDate>
    <description>DZone Snippets: session code</description>
    <item>
      <title>Getting the _session_id from SWFUpload (Flash 8 multiple file uploader)</title>
      <link>http://snippets.dzone.com/posts/show/3118</link>
      <description>It appears that Ruby's CGI::Session class will not use the _session_id in the query string when the Request is a POST.&lt;br /&gt;&lt;br /&gt;Normally, a POST-type request occurs when a form is submitted to the server (e.g. a Rails application).  In this scenario, there is an easy workaround since we can send the _session_id as a hidden field.&lt;br /&gt;&lt;br /&gt;With Flash 8, however, there is no way to add a 'hidden field' to the multi-part form data, thus Rails will fail to recognize the _session_id in the query string portion of our request.&lt;br /&gt;&lt;br /&gt;Here is a hackish work-around:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# The following code is a work-around for the&lt;br /&gt;# Flash 8 bug that prevents our multiple file uploader&lt;br /&gt;# from sending the _session_id.  Here, we hack the&lt;br /&gt;# Session#initialize method and force the session_id&lt;br /&gt;# to load from the query string via the request uri. &lt;br /&gt;# (Tested on Lighttpd)&lt;br /&gt;&lt;br /&gt;class CGI::Session&lt;br /&gt;  alias original_initialize initialize&lt;br /&gt;  def initialize(request, option = {})&lt;br /&gt;    session_key = option['session_key'] || '_session_id'&lt;br /&gt;    option['session_id'] =&lt;br /&gt;      request.env_table["REQUEST_URI"][0..-1].&lt;br /&gt;      scan(/#{session_key}=(.*?)(&amp;.*?)*$/).&lt;br /&gt;      flatten.first&lt;br /&gt;    original_initialize(request, option)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 10 Dec 2006 03:14:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3118</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
  </channel>
</rss>
