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