|
@@ -1,4 +1,4 @@
|
|
|
-# coding=utf-8
|
|
|
+#coding=utf-8
|
|
|
import os
|
|
|
|
|
|
import tornado.httpserver
|
|
@@ -14,6 +14,7 @@ class Application(tornado.web.Application):
|
|
|
def __init__(self):
|
|
|
handlers = [
|
|
|
(r"/", MainHandler),
|
|
|
+ (r"/download", GenFileStreamerHandler),
|
|
|
]
|
|
|
settings = dict(
|
|
|
template_path=os.path.join(os.path.dirname(__file__), "templates"),
|
|
@@ -25,6 +26,7 @@ class Application(tornado.web.Application):
|
|
|
|
|
|
class MainHandler(tornado.web.RequestHandler):
|
|
|
def get(self):
|
|
|
+
|
|
|
self.render(
|
|
|
"index.html",
|
|
|
title = """Preservation of three-dimensional anatomy in phosphatized
|
|
@@ -35,15 +37,48 @@ class MainHandler(tornado.web.RequestHandler):
|
|
|
University of Bonn, Bonn, Germany; ANKA/Institute for Photon Science and
|
|
|
Synchrotron Radiation, Karlsruhe Institute of Technology, Eggenstein-Leopoldshafen,
|
|
|
Germany; Department of Agricultural and Environmental Sciences, Clemson University,
|
|
|
- Clemson, United States; State Museum of Natural History Stuttgart, Stuttgart,Germany;
|
|
|
+ Clemson, United States; State Museum of Natural History Stuttgart, Stuttgart, Germany;
|
|
|
Institute of Crop Science and Resource Conservation, University of Bonn, Bonn, Germany;
|
|
|
Laboratory for Applications of Synchrotron Radiation, Karlsruhe Institute of Technology,
|
|
|
- Karlsruhe, Germany"""
|
|
|
+ Karlsruhe, Germany""",
|
|
|
+ data_list = [
|
|
|
+ "NRM-PZ_Ar65716",
|
|
|
+ "Saab",
|
|
|
+ "Mercedes",
|
|
|
+ "Audi"],
|
|
|
+ desc = "<i>Xenomorphia resurrecta</i>, male; well-preserved, head hollow",
|
|
|
+ data_size = "1.3 GB"
|
|
|
)
|
|
|
|
|
|
|
|
|
+class GenFileStreamerHandler(tornado.web.RequestHandler):
|
|
|
+ # 0.5 MB
|
|
|
+ CHUNK_SIZE = 512000
|
|
|
+ #def initialize(self, file_path):
|
|
|
+ # self.path = file_path
|
|
|
+ @tornado.web.asynchronous
|
|
|
+ @tornado.gen.engine
|
|
|
+ def get(self):
|
|
|
+ #print self.get_arguments("did")
|
|
|
+ self.path = '/Users/ntj/Development/fossil/data/01_NRM-PZ_Ar65716/test.zip'
|
|
|
+ file_name = "01_NRM-PZ_Ar65716.zip"
|
|
|
+ #self.set_header("Content-Type", "text/plain")
|
|
|
+ self.set_header('Content-Type', 'application/octet-stream')
|
|
|
+ self.set_header('Content-Disposition', 'attachment; filename=' + file_name)
|
|
|
+ self.set_header("Content-Length", os.path.getsize(self.path))
|
|
|
+ self.flush()
|
|
|
+ fd = open(self.path, "rb")
|
|
|
+ data = fd.read(self.CHUNK_SIZE)
|
|
|
+ while data:
|
|
|
+ self.write(data)
|
|
|
+ yield tornado.gen.Task(self.flush)
|
|
|
+ data = fd.read(self.CHUNK_SIZE)
|
|
|
+ fd.close()
|
|
|
+ self.finish()
|
|
|
+
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
tornado.options.parse_command_line()
|
|
|
http_server = tornado.httpserver.HTTPServer(Application())
|
|
|
http_server.listen(options.port)
|
|
|
- tornado.ioloop.IOLoop.instance().start()
|
|
|
+ tornado.ioloop.IOLoop.instance().start()
|