---------flash_session_cookie_middleware.rb require 'rack/utils'
class FlashSessionCookieMiddleware def initialize(app, session_key = '_session_id') @app = app @session_key = session_key end
def call(env) if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/ req = Rack::Request.new(env) params = ::Rack::Utils.parse_query(env['QUERY_STRING']) env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil? end @app.call(env) end end
------ controller def create @asset = Asset.new(params[:asset])
respond_to do |format| if params[:Filedata] @asset = Asset.new :swf_uploaded_data => params[:Filedata] @asset.user = current_user @asset.save!
format.html { render :text => @asset.image.url(:thumb) } format.xml { render :nothing => true }
else if @asset.save flash[:notice] = 'Created' format.html { redirect_to(@asset) } format.xml { render :xml => @asset, :status => :created, :location => @asset } else format.html { render :action => "new" } format.xml { render :xml => @asset.errors, :status => :unprocessable_entity } end end end end
-------- new.html.erb
<h1>New</h1>
<script type='text/javascript'> var swfu;
window.onload = function () { swfu = new SWFUpload({ upload_url : '<%= new_asset_path_with_session_information %>', flash_url : '/flash/swfupload.swf',
// Button settings button_image_url: "/images/TestImageNoText_65x29.png", // Relative to the Flash file button_width: "65", button_height: "29", button_placeholder_id: "spanButtonPlaceHolder", button_text: '<span class="theFont">Hello</span>', button_text_style: ".theFont { font-size: 16; }", button_text_left_padding: 12, button_text_top_padding: 3,
file_size_limit : '10000', file_types : '*.jpg', file_types_description : 'JPG Images', file_upload_limit : '0', custom_settings : { progressTarget : "fsUploadProgress" },
file_queue_error_handler : fileQueueError, file_dialog_complete_handler : fileDialogComplete, upload_progress_handler : uploadProgress, upload_error_handler : uploadError, upload_success_handler : uploadSuccess, upload_complete_handler : uploadComplete,
post_params : { authenticity_token : '<%= u form_authenticity_token -%>', },
custom_settings : { upload_target : 'divFileProgressContainer', },
debug: false
}); }; </script>
<div style="margin: 0px 10px;"> <div>
<% form_for(@asset) do |f| %> <fieldset> <div id="divStatus">0 Files Uploaded</div> <div> <span id="spanButtonPlaceHolder"></span> </div> </fieldset> <% end %>
</div> <div id="divFileProgressContainer" style="height: 75px;"></div> <div id="thumbnails"></div>
<p><%= link_to 'back', assets_path %></p> </div>
Once the upload completes, the browser throws a 406 error, despite the image uploading.