Tornado implementing File Download

Source: Internet
Author: User

Class Spockdataintegrationdownloadhandler (Tornado.web.RequestHandler): Def post (self): Selectname = Self.get_arg Ument (' selectname ') json_string = {} "" "puts the request parameter into Dict" "" type = self.get_argument (' t Ype ') StartTime = self.get_argument (' starttime ') Endtime = self.get_argument (' end_time ') json_s        tring[' starttime ' = starttime json_string[' endtime '] = endtime json_string[' type '] = Type "" " Generate JSON file "" "If Json_string:filepath = './jsonfile.conf ' If os.path.exists (filepat          h): Os.remove (filepath) FF = open (filepath, ' W ') json.dump (json_string, FF) # writes JSON-formatted data to a file Ff.close () "" "Download file" "filename =" jsonfile.conf "Self.set_header ( ' Content-type ', ' Application/octet-stream ') self.set_header (' content-disposition ', ' attachment; filename= ' + fil ENAME) buf_size = 4096 with open (Os.path.join (", filepath), ' RB ') as F:while true:data = F.read (buf_si Ze) if not data:break self.write (data) self.finish ()



Tornado implementing File Download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.