attachment filename 中文名浏览器乱码

python3.6+ tornado

支持中文,()

浏览器乱码支持

        
        userAgent = req_headers['User-Agent']
        # IE浏览器 
        if 'MSIE' in userAgent or 'Trident' in userAgent or 'Edge' in userAgent:
            output_file_name = parse.quote(output_file_name)
        #其他浏览器
        else:
            output_file_name = output_file_name.encode('utf-8').decode('ISO-8859-1')
            
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header(
            'Content-Disposition', f"attachment; filename=\"{output_file_name}\"")
        with open(output_file_path, 'rb') as fp:
            data = fp.read()
            return self.finish(data)

你可能感兴趣的:(attachment filename 中文名浏览器乱码)