Skip to content

Instantly share code, notes, and snippets.

@morganp
Created May 1, 2010 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morganp/386495 to your computer and use it in GitHub Desktop.
Save morganp/386495 to your computer and use it in GitHub Desktop.
# Sinatra method for handling file uploads
# based on http://pastie.caboo.se/134681
require 'rubygems'
require 'sinatra'
get '/upload' do
erb '<form action="upload" method="post" enctype="multipart/form-data" accept-charset="utf-8">
<input type="file" name="uploaded_data" id="uploaded_data">
<p><input type="submit" value="Continue"></p>
</form>'
end
post '/upload' do
FileUtils.mkdir_p('./Uploads/')
FileUtils.mv(params[:uploaded_data][:tempfile].path, "./Uploads/#{params[:uploaded_data][:filename]}")
erb 'Upload Complete'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment