后端server返回excel的base64时,文件名包含中文报错
发现文件名有中文名字,所以导致错误,编码是latin-1编码, 所以我们需要将文件名编码成utf-8再解码成latin-1。
self.set_header('Content-Type', 'application/octet-stream')
self.set_header('Content-Disposition', 'attachment; filename=' + os.path.basename(path).encode("utf-8").decode("latin1"))
又遇到问题,前端从头中获取文件名,文件名乱码。放弃上面的方法,改为
from tornado.escape import url_escape
self.set_header('Content-Type', 'application/octet-stream')
self.set_header('Content-Disposition', 'attachment; filename=' + url_escape(os.path.basename(url)))
网友评论