Sha256: 2b8f7b8edf9cb9ddaae82f2ff15807c54da0af07ee5e0496b17fcbe7680ba620
Contents?: true
Size: 974 Bytes
Versions: 6
Compression:
Stored size: 974 Bytes
Contents
# Running this example: # # m2sh load -config mongrel2.conf # bundle exec foreman start # # Browse now to http://localhost:6767/uploading to see the effect. # # This example is not threadsafe ! $stdout.sync = true $stderr.sync = true require 'rack' require 'pathname' use Rack::ContentLength size = 0 app = Proc.new do |env| req = Rack::Request.new(env) if req.post? size = req.params["file"][:tempfile].size.to_s rescue size = 0 end note = req.post?? "You submitted file of size: #{size}" : "Last submitted file was of size: #{size}" body = <<-EOF <html> <body> <form name="uploading" id="uploading_form" method="post" enctype="multipart/form-data" action="/uploading"> <input type="file" name="file" id="file"></input> <input type="submit" name="submit" id="submit">Submit</input> </form> <p>#{note}</p> </body> </html> EOF [200, {'Content-Type' => 'text/html'}, [body]] end run app
Version data entries
6 entries across 6 versions & 1 rubygems