forms - File upload validation Tornado Python -


I have found this example to upload files to a server using the Tornado Python Web framework, but the thing is If there is no error in handling, if there is no file attached then it returns a 500 error. The idea is to set the upload file field as optional, not mandatory.

Can you give me a hand?

I think it can be an easy solution, but I am a very newbie.

Thank you in advance!

Googleing I found this solution: Import Tornado LOLOP import taranto. WEP UPLOAD_FILE_PATH = 'Main article:' / path / to / files / 'class mainhandler (Tornado.web request handler): Def find (self): args = dict (user name =' visitor ') self.render (' Home.html ', ** args) Category UploadHandler (Tornado.web Request Handler): def post (self): user name = self if self.request.files.get (' uploadfile ', none) .get_argument (' File name = uploadFile ['filename'] FileObj = open (UPLOAD_FILE_PATH + username + filename, 'wb') file: obz Written (upload file ['Body']) self.redirect ('/') application = tornado.web.Application ([('r' / ', manhandler), (' / upload ', uploadhandler)], template_path =' templates', debug = True) If ___name__ == '__ main__': application.listen (8888) Ternado Loloop.IOLoop.instance (). Start ()

The following is the condition placed before the file request: if self.request.files.get ('uploadfile', none): < / p>

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -