Skip to content

Instantly share code, notes, and snippets.

@ichiban
Created January 20, 2012 16:17
Show Gist options
  • Save ichiban/1648104 to your computer and use it in GitHub Desktop.
Save ichiban/1648104 to your computer and use it in GitHub Desktop.
example for big-upload
require 'sinatra'
require 'yajl/json_gem'
set(:mongrel2_upload) do |value|
condition do
case value
when :start
request.env.key?('x-mongrel2-upload-start')
when :done
request.env.key?('x-mongrel2-upload-done')
else
false
end
end
end
before do
p request # no x-mongrel2-upload-* headers?
end
put '/ok', :mongrel2_upload => :done do
puts 'ok done'
send_file request['x-mongrel2-upload-done'] # show the uploaded file
end
put '/ok', :mongrel2_upload => :start do
puts 'ok start'
throw :async # continue the upload
end
put '/ng', :mongrel2_upload => :done do
puts 'ng done'
send_file request['x-mongrel2-upload-done'] # this will never happen.
end
put '/ng', :mongrel2_upload => :start do
puts 'ng start'
'' # cancel the upload
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment