Forked from gavinheavyside/trivial_file_upload_service.rb
Created
December 15, 2010 20:54
-
-
Save efrenfuentes/742597 to your computer and use it in GitHub Desktop.
Trivial file upload service
This file contains 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' | |
require 'fileutils' | |
# upload with: | |
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename | |
post '/:name/:filename' do | |
userdir = File.join("files", params[:name]) | |
FileUtils.mkdir_p(userdir) | |
filename = File.join(userdir, params[:filename]) | |
datafile = params[:data] | |
# "#{datafile[:tempfile].inspect}\n" | |
File.open(filename, 'wb') do |file| | |
file.write(datafile[:tempfile].read) | |
end | |
"wrote to #{filename}\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment