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)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容