Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Install mongrel, run with:
- # jruby upload_handler.rb [host] [port] (default localhost:3000)
- # Try uploading files of various sizes
- require 'rubygems'
- require 'mongrel'
- class UploadHandler < Mongrel::HttpHandler
- def process(request, response)
- response.start(200) do |head,out|
- head["Content-Type"] = "text/html"
- out.write upload_form(request.body)
- end
- end
- def upload_form(body)
- data = if body
- "<p>body.path = #{body.path if body.respond_to?(:path)}</p>\n" +
- "<p>body.length = #{body.length}</p><br/>\n"
- else
- ""
- end
- %{#{data}<form method="POST" action="/" enctype="multipart/form-data">
- <input type="file" name="uploaded_data"/>
- <input type="submit" name="Upload"/>
- </form>}
- end
- end
- host = ARGV[0]
- host ||= "localhost"
- port = ARGV[1]
- port ||= 3000
- config = Mongrel::Configurator.new :host => host, :port => port do
- listener do
- uri "/", :handler => UploadHandler.new
- end
- trap("INT") { stop }
- run
- end
- puts "Mongrel running on #{host}:#{port}"
- config.join
Add Comment
Please, Sign In to add comment