Created
January 20, 2012 16:17
-
-
Save ichiban/1648104 to your computer and use it in GitHub Desktop.
example for big-upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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