Commits

sempr committed 8d04751

MOD: test3 for base64 upload

  • Participants
  • Parent commits 64b6b22

Comments (0)

Files changed (2)

 import tornado.gen
 import sockjs.tornado
 import json
+import base64
 
 from tornado.options import define, options
 
         handlers = [
             (r"/", IndexHandler),
             (r"/new", CreateHandler),
+            (r"/test", TestHandler),
+            (r"/test2", Test2Handler),
             (r"/list", ListHandler),
             (r'/(\d{8})/upload',UploadHandler),
             (r'/(\d{8})/list',ListContentHandler),
             self.set_status(404)
             self.finish()
 
+class Test2Handler(BaseHandler):
+    def get(self):
+        self.render('test2.html')
+class TestHandler(BaseHandler):
+    def post(self):
+        binary = base64.b64decode(self.get_argument('data'))
+        filename = self.get_argument('filename')
+        #file = {'body':binary,'filename':filename,'content_type':'application/file'}
+            
+        file_path = os.path.join(os.path.dirname(__file__),'test.txt')
+        f = open(file_path, 'wb')
+#        print binary, len(binary),
+        f.write(binary)
+        f.close()
+#        print self.get_argument('data')
+#        print self.get_argument('filename')
+        pass
+    def get(self):
+        self.render('test3.html')
+    
+
 class UploadHandler(BaseHandler):
     """ Handle Upload, and QR Code """
     def get(self, channel):

templates/test3.html

 		var blob = file.webkitSlice(0)
 		reader.readAsBinaryString(blob);
 		reader.onload = function(e){
-            
+            //console.log(this.result) 
+            var str = $.base64.encode(this.result)
+            $.post('/test',{'filename':'test.txt','data':str},function(){});
         }
 	}
   document.getElementById('file').addEventListener('change', handleFileSelect, false);
 </script>
 </body>
 
-</html>
+</html>