Permalink
Browse files

playing with some local file upload stuff

  • Loading branch information...
1 parent ce68a3b commit 03115469c340e4bb16db40c966c3c3365ef7bb12 Andrew Havens committed Feb 20, 2012
Showing with 46 additions and 0 deletions.
  1. +1 −0 lib/mad_chatter.rb
  2. +1 −0 lib/mad_chatter/server.rb
  3. +34 −0 lib/mad_chatter/servers/http.rb
  4. +5 −0 mad_chatter.gemspec
  5. +5 −0 templates/web/index.html
View
@@ -10,6 +10,7 @@
require 'mad_chatter/config'
require 'mad_chatter/server'
+require 'mad_chatter/servers/http'
require 'mad_chatter/servers/em_websocket'
require 'mad_chatter/channel'
@@ -14,6 +14,7 @@ def start
EM.run do
puts "Starting Mad Chatter Web Socket server on port #{@config['websocket_port']}."
@server.start
+ MadChater::Servers::Http.run!({:port=>3001})
end
end
@@ -0,0 +1,34 @@
+# require 'sqlite3'
+# require 'sequel'
+# require 'carrierwave/sequel'
+require 'sinatra/base'
+
+module MadChatter
+ module Servers
+ class Http < Sinatra::Base
+
+ class FileUploader < CarrierWave::Uploader::Base
+ storage :file
+ end
+
+ # class FileUpload < Sequel::Model
+ # mount_uploader :file, FileUploader
+ # end
+
+ # set :environment, :production
+ # set :root, File.dirname(__FILE__)
+ # set :public_folder, File.dirname(__FILE__) + '/public'
+ # set :views, File.dirname(__FILE__) + '/views'
+
+ post '/upload' do
+ puts 'upload received'
+ # upload = Upload.new
+ # upload.file = params[:file]
+ # upload.save
+ uploader = FileUploader.new
+ uploader.store!(params[:file])
+ puts uploader.url
+ end
+ end
+ end
+end
View
@@ -22,6 +22,11 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "eventmachine"
s.add_runtime_dependency "em-websocket"
s.add_runtime_dependency "daemons", "1.1.4"
+ s.add_runtime_dependency 'sinatra'
+ s.add_runtime_dependency 'carrierwave'
+ # s.add_runtime_dependency 'sqlite3'
+ # s.add_runtime_dependency 'sequel'
+ # s.add_runtime_dependency 'carrierwave/sequel'
s.add_development_dependency "rspec"
# s.add_development_dependency "shoulda" # do we need this?
@@ -26,6 +26,11 @@
</head>
<body>
+
+ <form action="http://localhost:3001/upload" method="post" enctype="multipart/form-data"></div>
+ <p><input type="file" name="file" /></p>
+ <p><input type="submit" name="submit" value="Upload" /></p>
+ </form>
<div id="upgrade_flash" class="container-fluid" style="display:none">
<h1>Mad Chatter</h1>

0 comments on commit 0311546

Please sign in to comment.