Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. # Install mongrel, run with:
  2. # jruby upload_handler.rb [host] [port] (default localhost:3000)
  3. # Try uploading files of various sizes
  4.  
  5. require 'rubygems'
  6. require 'mongrel'
  7.  
  8. class UploadHandler < Mongrel::HttpHandler
  9. def process(request, response)
  10. response.start(200) do |head,out|
  11. head["Content-Type"] = "text/html"
  12. out.write upload_form(request.body)
  13. end
  14. end
  15.  
  16. def upload_form(body)
  17. data = if body
  18. "<p>body.path = #{body.path if body.respond_to?(:path)}</p>\n" +
  19. "<p>body.length = #{body.length}</p><br/>\n"
  20. else
  21. ""
  22. end
  23. %{#{data}<form method="POST" action="/" enctype="multipart/form-data">
  24. <input type="file" name="uploaded_data"/>
  25. <input type="submit" name="Upload"/>
  26. </form>}
  27. end
  28. end
  29.  
  30. host = ARGV[0]
  31. host ||= "localhost"
  32. port = ARGV[1]
  33. port ||= 3000
  34.  
  35.  
  36. config = Mongrel::Configurator.new :host => host, :port => port do
  37. listener do
  38. uri "/", :handler => UploadHandler.new
  39. end
  40.  
  41. trap("INT") { stop }
  42. run
  43. end
  44.  
  45. puts "Mongrel running on #{host}:#{port}"
  46. config.join
Add Comment
Please, Sign In to add comment