Skip to content

Instantly share code, notes, and snippets.

@rufo
Created May 11, 2011 19:41
Show Gist options
  • Save rufo/967165 to your computer and use it in GitHub Desktop.
Save rufo/967165 to your computer and use it in GitHub Desktop.
SWFUpload Rails 2.3 server side code
ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:session_key])
# just so you get an idea of what params will look like...
# Flash uploads with mime type application/octet-stream, so you need to fix it
# you can either set it manually via extension or use the mime-types gem
def process_bulk_upload
@asset = Asset.find(params[:asset_id])
mime_type = MIME::Types.type_for(params["Filename"]).to_s
case mime_type
when "application/pdf"
@asset.pdf_preview = params["Filedata"]
@asset.pdf_preview_content_type = mime_type
when "image/jpeg"
@asset.thumbnail = params["Filedata"]
@asset.thumbnail = mime_type
else
raise "Improper type"
end
@asset.save!
head :ok
end
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/
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment