From 46e146e633f87fad663fcd4f132b2676112a6ab0 Mon Sep 17 00:00:00 2001 From: link Date: Wed, 15 Feb 2023 17:31:20 +0800 Subject: [PATCH] Fix the download file name error problem (#896) --- route/v2.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/route/v2.go b/route/v2.go index 1bf7ba512..013a92d99 100644 --- a/route/v2.go +++ b/route/v2.go @@ -4,6 +4,7 @@ import ( "log" "net/http" "net/url" + "path" "path/filepath" "strconv" "strings" @@ -138,8 +139,10 @@ func InitV2DocRouter(docHTML string, docYAML string) http.Handler { } func InitFile() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - path := r.URL.Query().Get("path") - http.ServeFile(w, r, path) + filePath := r.URL.Query().Get("path") + fileName := path.Base(filePath) + w.Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(fileName)) + http.ServeFile(w, r, filePath) }) }