处理golang gin框架下载文件时中文文件名乱码问题

func Download(c *gin.Context) {
	c.Writer.WriteHeader(http.StatusOK)
	//设置文件类型
	c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
	// PathEscape 函数对中文做处理
	c.Header("Content-Disposition", "attachment; filename="+url.PathEscape("测试")+".xls")
	c.Header("Content-Transfer-Encoding", "binary")
	c.File("/Downloads/response.xls")
	return
}
posted @ 2023-12-04 18:24  熊先生不开玩笑  阅读(618)  评论(0)    收藏  举报