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
}
处理golang gin框架下载文件时中文文件名乱码问题
发布时间 2023-12-04 18:30:05作者: 熊先生不开玩笑