Skip to content

Instantly share code, notes, and snippets.

@witscher
Created June 28, 2012 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save witscher/3011497 to your computer and use it in GitHub Desktop.
Save witscher/3011497 to your computer and use it in GitHub Desktop.
very, very simple HTTP POST upload app
# 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