美文网首页
attachment filename 中文名浏览器乱码

attachment filename 中文名浏览器乱码

作者: Caca哒 | 来源:发表于2018-03-30 16:31 被阅读0次

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 中文名浏览器乱码

      本文链接:https://www.haomeiwen.com/subject/tmaefftx.html