-
-
Save manadart/4018749 to your computer and use it in GitHub Desktop.
Sinatra Upload
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' | |
include FileUtils::Verbose | |
get '/up' do | |
erb :form | |
end | |
post '/up' do | |
tmpfile = params[:file][:tempfile] | |
filename = params[:file][:filename] | |
cp(tmpfile.path, "public/#{filename}") | |
"Uploaded #{filename}" | |
end | |
__END__ | |
@@form | |
<html> | |
<body> | |
<form action="/up" enctype="multipart/form-data" method="POST"> | |
<input name="file" type="file" /> | |
<input type="submit" value="Upload" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment