Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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