Created
March 19, 2010 11:58
-
-
Save pfeilbr/337450 to your computer and use it in GitHub Desktop.
ruby sinatra file upload example
This file contains hidden or 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 'rubygems' | |
require 'sinatra/base' | |
class MyApp < Sinatra::Base | |
get '/' do | |
'myapp2 Hello world!' | |
end | |
get '/hello' do | |
html = "<pre>" | |
env.each do |k,v| | |
html += k + " = " + v.to_s + "<br/>" | |
end | |
html + "</pre>" | |
end | |
post '/form' do | |
html = "<pre>" | |
env.each do |k,v| | |
html += k + " = " + v.to_s + "<br/>" | |
end | |
html + "</pre>" | |
params.to_s | |
tmpfile = params[:file][:tempfile] | |
tmpfile.read | |
end | |
get '/form' do | |
%{ | |
<html> | |
<body> | |
<form action="form" method="post" enctype="multipart/form-data"> | |
<input type="file" name="file"/> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> | |
} | |
end | |
end | |
MyApp.run! :host => 'localhost', :port => 8082, :server => 'thin' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment