Created
June 28, 2012 13:49
-
-
Save witscher/3011497 to your computer and use it in GitHub Desktop.
very, very simple HTTP POST upload app
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
# set max_body_size and http_basic_auth in your nginx config | |
require 'rubygems' | |
require 'sinatra' | |
get '/' do | |
"none ya business" | |
end | |
post '/' do | |
@auth ||= Rack::Auth::Basic::Request.new(request.env) | |
username = @auth.username if @auth.provided? | |
if username | |
dir = '/opt/httpupload/' + username | |
Dir.mkdir(dir) unless File.exists?(dir) | |
if ( params['filedata'][:filename] =~ /.*\.(csv|xls|txt)$/ ) | |
File.open('/opt/httpupload/' + username + '/'+ params['filedata'][:filename], "w") do |f| | |
f.write(params['filedata'][:tempfile].read) | |
end | |
end | |
return "file uploaded." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment