Tornado – File Uploads


Quite often we’re in need of providing file upload mechanism on our website. Be it logs management or user profile management, support for file upload is a must. This blog describes how uploads be achieved with Tornado web server.

Example code:

In this code snippet;

  • When user browses to http://localhost:8888/, he is presented with file upload form (code below)
  • On browsing and selecting the appropriate file, the user clicks on upload
  • The file gets uploaded and the user gets a message with filename & the uploaded location

In the upload form, its important to note the usage of below tags for file uploads:

  • enctype=”multipart/form-data”
  • input type=”file

As a side note, if you print fileinfo variable, you would observe a dictionary with contents and meta-data of file being uploaded

fileinfo is {'body': 'This is a file upload test for Tornado!!\n', 'content_type': u'application/octet-stream', 'filename': u'fileuploadtest'}
Advertisements

2 thoughts on “Tornado – File Uploads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s