summary refs log tree commit diff
path: root/demo/webserver.py
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-08-14 18:38:42 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-08-14 18:38:56 +0200
commitf5973d8ddb1d972221370022459e9c750c079ad8 (patch)
treea9af648e684102f269f541423c259bc4b73907bf /demo/webserver.py
parentwebclient: You can now paginate in rooms. Defaults to 10 messages, with a but... (diff)
downloadsynapse-f5973d8ddb1d972221370022459e9c750c079ad8.tar.xz
Create a temporary upload service server side (by hacking demos/webserver.py) and client side with an angularjs service component.
Diffstat (limited to 'demo/webserver.py')
-rw-r--r--demo/webserver.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/demo/webserver.py b/demo/webserver.py
index 78f3213540..875095c877 100644
--- a/demo/webserver.py
+++ b/demo/webserver.py
@@ -2,9 +2,32 @@ import argparse
 import BaseHTTPServer
 import os
 import SimpleHTTPServer
+import cgi, logging
 
 from daemonize import Daemonize
 
+class SimpleHTTPRequestHandlerWithPOST(SimpleHTTPServer.SimpleHTTPRequestHandler):
+    UPLOAD_PATH = "upload"
+
+    """
+    Accept all post request as file upload
+    """
+    def do_POST(self):
+
+        path = os.path.join(self.UPLOAD_PATH, os.path.basename(self.path))
+        length = self.headers['content-length']
+        data = self.rfile.read(int(length))
+
+        with open(path, 'wb') as fh:
+            fh.write(data)
+
+        self.send_response(200)
+        self.send_header('Content-Type', 'application/json')
+        self.end_headers()
+
+        # Return the absolute path of the uploaded file
+        self.wfile.write('{"url":"/%s"}' % path)
+
 
 def setup():
     parser = argparse.ArgumentParser()
@@ -19,7 +42,7 @@ def setup():
 
     httpd = BaseHTTPServer.HTTPServer(
         ('', args.port),
-        SimpleHTTPServer.SimpleHTTPRequestHandler
+        SimpleHTTPRequestHandlerWithPOST
     )
 
     def run():