From 68bdf7deb4983c47dfbe3b8be18e206855f09426 Mon Sep 17 00:00:00 2001 From: med-one Date: Tue, 1 Mar 2022 18:32:11 +0800 Subject: [PATCH] revert(fix bug , add nexttime feature): ServeFileDownload File name Chinese garbled repair --- net/ghttp/ghttp_response.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ghttp/ghttp_response.go b/net/ghttp/ghttp_response.go index eb6f89ef1..01312f0fd 100644 --- a/net/ghttp/ghttp_response.go +++ b/net/ghttp/ghttp_response.go @@ -11,6 +11,7 @@ import ( "bytes" "fmt" "net/http" + "net/url" "github.com/gogf/gf/v2/net/gtrace" "github.com/gogf/gf/v2/os/gfile" @@ -91,7 +92,7 @@ func (r *Response) ServeFileDownload(path string, name ...string) { } r.Header().Set("Content-Type", "application/force-download") r.Header().Set("Accept-Ranges", "bytes") - r.Header().Set("Content-Disposition", fmt.Sprintf(`attachment;filename="%s"`, downloadName)) + r.Header().Set("Content-Disposition", fmt.Sprintf(`attachment;filename="%s"`, url.QueryEscape(downloadName))) r.Server.serveFile(r.Request, serveFile) }