This is my solution == >
Python code:
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.httpserver
from tornado.options import options, define
define("port", default=8888, help="run on the given port", type=int)
class Appliaction(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", HomeHandler),
(r"/upload", UploadHandler),
]
settings = dict(
debug = True,
)
super(Appliaction, self).__init__(handlers, **settings)
class HomeHandler(tornado.web.RequestHandler):
def get(self):
self.render('form.html')
MAX_STREAMED_SIZE = 1024 * 1024 * 1024
@tornado.web.stream_request_body
class UploadHandler(tornado.web.RequestHandler):
def initialize(self):
self.bytes_read = 0
self.data = b''
def prepare(self):
self.request.connection.set_max_body_size(MAX_STREAMED_SIZE)
def data_received(self, chunck):
self.bytes_read += len(chunck)
self.data += chunck
def post(self):
this_request = self.request
value = self.data
with open('file', 'wb') as f:
f.write(value)
def Main():
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Appliaction())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
Main()
Html code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload</title>
</head>
<body>
<h1>Upload</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<br />
<input type="submit" value="upload" />
</form>
</body>
</html>