Python Tornado使用上传的json文件

时间:2018-08-08 15:13:30

标签: python tornado

我已经创建了处理程序和所有必要的内容来上传文件。我可以在uploads /目录中看到上传的文件,但是无法对上传的文件执行任何操作。

class Userform(tornado.web.RequestHandler):
def get(self):
    self.render("fileuploadform.html")


class Upload(tornado.web.RequestHandler):
    def post(self):
     fileinfo = self.request.files['filearg'][0]
     print ("fileinfo is", fileinfo)
     fname = fileinfo['filename']
     extn = os.path.splitext(fname)[1]
     fname = fname.replace('.json','')
     cname = fname + extn
     self.finish(fileName + " is uploaded!! Check %s folder" %__UPLOADS__)

application = tornado.web.Application([
    (r"/", Userform),
    (r"/upload", Upload),
    ], debug=True)





if __name__ == "__main__":
application.listen(8000)
tornado.ioloop.IOLoop.instance().start()

0 个答案:

没有答案