Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
# or just go to http://localhost:4567/user/filename with a browser
get '/:name/:filename' do
erb :form
post '/:name/:filename' do
userdir = File.join("files", params[:name])
filename = File.join(userdir, params[:filename])
datafile = params[:data]
# "#{datafile[:tempfile].inspect}\n"
File.copy(datafile[:tempfile], filename), 'wb') do |file|
# file.write(datafile[:tempfile].read)
"wrote to #{filename}\n"
@@ form
<form action="" method="post" enctype="multipart/form-data">
<label for="file">File:</label>
<input type="file" name="file">
<input name="commit" type="submit" value="Upload" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment