<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Rails 2.3.4 and SWFUpload &#8211; Rack Middleware for Flash Uploads that Degrade Gracefully</title>
	<atom:link href="http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/feed/" rel="self" type="application/rss+xml" />
	<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/</link>
	<description>Rock{et}ing the interweb</description>
	<lastBuildDate>Sun, 25 Jul 2010 20:02:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Jan Foeh</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-530</link>
		<dc:creator>Jan Foeh</dc:creator>
		<pubDate>Tue, 15 Jun 2010 22:46:07 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-530</guid>
		<description>For anyone having the same problem David had, here&#039;s what I did: being sleep deprived and unable to come up with an elegant solution, I resorted to an ugly hack in application_controller.rb.


  before_filter :fix_missing_session, :only =&gt; :edit

    private

  def fix_missing_session
    if request.get? &amp;&amp; cookies[ActionController::Base.session_options[:key]].blank?
      session[:the_answer] = 42
      redirect_to request.headers[&quot;REQUEST_URI&quot;] and return
    end
  end

Whenever one of the edit pages with SWFupload in them is loaded without the session cookie being set, I set the session and reload the page. A better solution would probably be to encode a session string manually, or to calculate a new csrf token matching the empty session...</description>
		<content:encoded><![CDATA[<p>For anyone having the same problem David had, here&#8217;s what I did: being sleep deprived and unable to come up with an elegant solution, I resorted to an ugly hack in application_controller.rb.</p>
<p>  before_filter :fix_missing_session, <img src='http://jetpackweb.com/blog/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly =&gt; :edit</p>
<p>    private</p>
<p>  def fix_missing_session<br />
    if request.get? &amp;&amp; cookies[ActionController::Base.session_options[:key]].blank?<br />
      session[:the_answer] = 42<br />
      redirect_to request.headers["REQUEST_URI"] and return<br />
    end<br />
  end</p>
<p>Whenever one of the edit pages with SWFupload in them is loaded without the session cookie being set, I set the session and reload the page. A better solution would probably be to encode a session string manually, or to calculate a new csrf token matching the empty session&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: File uploads in Ruby on Rails &#124; Space Babies</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-315</link>
		<dc:creator>File uploads in Ruby on Rails &#124; Space Babies</dc:creator>
		<pubDate>Sat, 20 Feb 2010 11:04:48 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-315</guid>
		<description>[...] That&#8217;s just sad, people. It makes Jesus cry and all that stuff. Luckily here is a good post explaining the procedure. Yes, we need to write a custom piece of middleware because Flash is [...]</description>
		<content:encoded><![CDATA[<p>[...] That&#8217;s just sad, people. It makes Jesus cry and all that stuff. Luckily here is a good post explaining the procedure. Yes, we need to write a custom piece of middleware because Flash is [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David North</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-284</link>
		<dc:creator>David North</dc:creator>
		<pubDate>Mon, 01 Feb 2010 12:39:04 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-284</guid>
		<description>I think this is due to the session data I&#039;m sending being out of date. Although I&#039;m initializing the session by writing a value to it on the request that displays my upload form, the contents of cookies[session_key] reflect what was loaded from the cookies, its not until the next request that this value is correct (including the csrf token). Somehow I need to get a value for the session data that reflects the current state of the session so it&#039;ll match with the authenticity token in the upload request.</description>
		<content:encoded><![CDATA[<p>I think this is due to the session data I&#8217;m sending being out of date. Although I&#8217;m initializing the session by writing a value to it on the request that displays my upload form, the contents of cookies[session_key] reflect what was loaded from the cookies, its not until the next request that this value is correct (including the csrf token). Somehow I need to get a value for the session data that reflects the current state of the session so it&#8217;ll match with the authenticity token in the upload request.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David North</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-283</link>
		<dc:creator>David North</dc:creator>
		<pubDate>Mon, 01 Feb 2010 12:34:14 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-283</guid>
		<description>I can see from the logs that the token is correct, otherwise it wouldn&#039;t work on subsequent requests. Same goes for the session data.
On the first request, my session doesn&#039;t contain the key &quot;_csrf_token&quot;, that seems to be responsible for the session mis-match that results in the IAT error. 

When I write something to the session, on the next request I can see that _csrf_token exists and the session data is longer. Then the upload will work.</description>
		<content:encoded><![CDATA[<p>I can see from the logs that the token is correct, otherwise it wouldn&#8217;t work on subsequent requests. Same goes for the session data.<br />
On the first request, my session doesn&#8217;t contain the key &#8220;_csrf_token&#8221;, that seems to be responsible for the session mis-match that results in the IAT error. </p>
<p>When I write something to the session, on the next request I can see that _csrf_token exists and the session data is longer. Then the upload will work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Duncan</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-268</link>
		<dc:creator>Mark Duncan</dc:creator>
		<pubDate>Wed, 27 Jan 2010 15:05:57 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-268</guid>
		<description>Sorry, stripped out the tags there -- i&#039;ll give it another go :)

&#039;scriptData&#039;	: { &#039;&lt;%= get_session_key %&gt;&#039; : &#039;&lt;%= u cookies[get_session_key] %&gt;&#039;, &#039;authenticity_token&#039; : &#039;&lt;%= u form_authenticity_token if protect_against_forgery? %&gt;&#039; },</description>
		<content:encoded><![CDATA[<p>Sorry, stripped out the tags there &#8212; i&#8217;ll give it another go <img src='http://jetpackweb.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8216;scriptData&#8217;	: { &#8216;&lt;%= get_session_key %&gt;&#8217; : &#8216;&lt;%= u cookies[get_session_key] %&gt;&#8217;, &#8216;authenticity_token&#8217; : &#8216;&lt;%= u form_authenticity_token if protect_against_forgery? %&gt;&#8217; },</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Duncan</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-267</link>
		<dc:creator>Mark Duncan</dc:creator>
		<pubDate>Wed, 27 Jan 2010 15:04:25 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-267</guid>
		<description>How are you passing the authenticity token to javascript. I was having an issue with intermittent IAT errors that were caused by the token having a space in it that was getting decoded as %20.

This did the trick for me, don&#039;t know if it&#039;s related to your issue but worth a try.

&#039;scriptData&#039;	: { &#039;&#039; : &#039;&#039;, &#039;authenticity_token&#039; : &#039;&#039; },</description>
		<content:encoded><![CDATA[<p>How are you passing the authenticity token to javascript. I was having an issue with intermittent IAT errors that were caused by the token having a space in it that was getting decoded as %20.</p>
<p>This did the trick for me, don&#8217;t know if it&#8217;s related to your issue but worth a try.</p>
<p>&#8216;scriptData&#8217;	: { &#8221; : &#8221;, &#8216;authenticity_token&#8217; : &#8221; },</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David North</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-265</link>
		<dc:creator>David North</dc:creator>
		<pubDate>Tue, 26 Jan 2010 13:54:24 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-265</guid>
		<description>I&#039;ve got all this working great except I always get InvalidAuthenticityToken on the first attempt with a fresh browser session.

In the log, I can see that I&#039;m getting the authenticity token correctly in the params.
The middleware is loaded before CookieStore and with some debug code I can see that it is adding the session data to HTTP_COOKIE e.g.

&quot;_myapp_session=BAh7BjoPc2Vzc2lvbl9pZCIlNDg1ZTExMzY5MGY0ZmQxYmU4MzMwNmFhNTcwNjc1ZmU=--71c3a1f402926876eab548d22bcfd03cd159162e&quot;

I noticed this seems to be related to the session state, if some value has been written to the session in a request previous to the one that renders my upload interface it will work. However many pages are viewed before the upload form it won&#039;t work unless some value has been written to the session.

Any thoughts?</description>
		<content:encoded><![CDATA[<p>I&#8217;ve got all this working great except I always get InvalidAuthenticityToken on the first attempt with a fresh browser session.</p>
<p>In the log, I can see that I&#8217;m getting the authenticity token correctly in the params.<br />
The middleware is loaded before CookieStore and with some debug code I can see that it is adding the session data to HTTP_COOKIE e.g.</p>
<p>&#8220;_myapp_session=BAh7BjoPc2Vzc2lvbl9pZCIlNDg1ZTExMzY5MGY0ZmQxYmU4MzMwNmFhNTcwNjc1ZmU=&#8211;71c3a1f402926876eab548d22bcfd03cd159162e&#8221;</p>
<p>I noticed this seems to be related to the session state, if some value has been written to the session in a request previous to the one that renders my upload interface it will work. However many pages are viewed before the upload form it won&#8217;t work unless some value has been written to the session.</p>
<p>Any thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Duncan</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-263</link>
		<dc:creator>Mark Duncan</dc:creator>
		<pubDate>Fri, 22 Jan 2010 10:16:33 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-263</guid>
		<description>Finally found the root cause to the above problem, on windows the HTTP_ACCEPT is sent as text/* instead of */*. This can be fixed in the middleware.

def call(env)
if env[&#039;HTTP_USER_AGENT&#039;] =~ /^(Adobe&#124;Shockwave) Flash/
params = ::Rack::Request.new(env).params
env[&#039;HTTP_COOKIE&#039;] = [ @session_key, params[@session_key] ].join(&#039;=&#039;).freeze unless params[@session_key].nil?
env[&#039;HTTP_ACCEPT&#039;] = &#039;*/*&#039;
end
@app.call(env)
end</description>
		<content:encoded><![CDATA[<p>Finally found the root cause to the above problem, on windows the HTTP_ACCEPT is sent as text/* instead of */*. This can be fixed in the middleware.</p>
<p>def call(env)<br />
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/<br />
params = ::Rack::Request.new(env).params<br />
env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join(&#8216;=&#8217;).freeze unless params[@session_key].nil?<br />
env['HTTP_ACCEPT'] = &#8216;*/*&#8217;<br />
end<br />
@app.call(env)<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Duncan</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-259</link>
		<dc:creator>Mark Duncan</dc:creator>
		<pubDate>Wed, 20 Jan 2010 14:41:22 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-259</guid>
		<description>I managed to fix the error above with a nasty hack. When an upload is done the Mongrel..1-0 file is created first and then the RackMultipart...zvp-0 is created. The Mp3info line was happening before the RackMulti file was finished writing. I&#039;ve replaced the create action with

  def create
    require &#039;mp3info&#039;
    @timer = Time.now
    begin
			mp3_info = Mp3Info.new(params[:Filedata].path)
			
	
			logger.info(&quot;GOT MP3 INFO&quot;)
	    song = Song.new
	    song.artist = mp3_info.tag.artist
	    song.title = mp3_info.tag.title
	    song.length_in_seconds = mp3_info.length.to_i
	
	    params[:Filedata].content_type = MIME::Types.type_for(params[:Filedata].original_filename).to_s
	    song.track = params[:Filedata]
	    logger.info(&quot;GOT HERE&quot;);
	    song.save
	
	    render :text =&gt; [song.artist, song.title, song.convert_seconds_to_time].join(&quot; - &quot;)
	  rescue Mp3InfoError =&gt; e
	  	if @timer + 2.minutes  &quot;File error: &quot;+e.message
	  	else
	    	retry
	    end
	  rescue Exception =&gt; e
	    render :text =&gt; e.message
	 	end
  end

it&#039;s nasty but it does the job for now.</description>
		<content:encoded><![CDATA[<p>I managed to fix the error above with a nasty hack. When an upload is done the Mongrel..1-0 file is created first and then the RackMultipart&#8230;zvp-0 is created. The Mp3info line was happening before the RackMulti file was finished writing. I&#8217;ve replaced the create action with</p>
<p>  def create<br />
    require &#8216;mp3info&#8217;<br />
    @timer = Time.now<br />
    begin<br />
			mp3_info = Mp3Info.new(params[:Filedata].path)</p>
<p>			logger.info(&#8220;GOT MP3 INFO&#8221;)<br />
	    song = Song.new<br />
	    song.artist = mp3_info.tag.artist<br />
	    song.title = mp3_info.tag.title<br />
	    song.length_in_seconds = mp3_info.length.to_i</p>
<p>	    params[:Filedata].content_type = MIME::Types.type_for(params[:Filedata].original_filename).to_s<br />
	    song.track = params[:Filedata]<br />
	    logger.info(&#8220;GOT HERE&#8221;);<br />
	    song.save</p>
<p>	    render :text =&gt; [song.artist, song.title, song.convert_seconds_to_time].join(&#8221; &#8211; &#8220;)<br />
	  rescue Mp3InfoError =&gt; e<br />
	  	if @timer + 2.minutes  &#8220;File error: &#8220;+e.message<br />
	  	else<br />
	    	retry<br />
	    end<br />
	  rescue Exception =&gt; e<br />
	    render :text =&gt; e.message<br />
	 	end<br />
  end</p>
<p>it&#8217;s nasty but it does the job for now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Duncan</title>
		<link>http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/#comment-258</link>
		<dc:creator>Mark Duncan</dc:creator>
		<pubDate>Wed, 20 Jan 2010 11:47:26 +0000</pubDate>
		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=523#comment-258</guid>
		<description>Hi,

I&#039;m having the same File Error message Axel mentions above, i&#039;ve dug into it a bit and it&#039;s an empty file error. I&#039;ve dumped the post-params and the filedata holds : Filedata&quot;=&gt;# when i watch that temp directory i&#039;m seeing two files created when i try to upload. RackMultipart20100120-4108-5olzvp-0 which is 0kb and a file named mongrel20100120-4108-16qghk1-0 which is 1kb bigger than the mp3 i&#039;m uploading, when i inspect it in a hex editor i can see the params are listed at the start. Anyone have any ideas what is happening?</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;m having the same File Error message Axel mentions above, i&#8217;ve dug into it a bit and it&#8217;s an empty file error. I&#8217;ve dumped the post-params and the filedata holds : Filedata&#8221;=&gt;# when i watch that temp directory i&#8217;m seeing two files created when i try to upload. RackMultipart20100120-4108-5olzvp-0 which is 0kb and a file named mongrel20100120-4108-16qghk1-0 which is 1kb bigger than the mp3 i&#8217;m uploading, when i inspect it in a hex editor i can see the params are listed at the start. Anyone have any ideas what is happening?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
