Skip to content

Instantly share code, notes, and snippets.

Created November 5, 2012 16:35
Show Gist options
  • Save anonymous/4018150 to your computer and use it in GitHub Desktop.
Save anonymous/4018150 to your computer and use it in GitHub Desktop.
Sinatra Upload
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