浏览代码

Fix the download file name error problem (#896)

link 2 年之前
父节点
当前提交
46e146e633
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      route/v2.go

+ 5 - 2
route/v2.go

@@ -4,6 +4,7 @@ import (
 	"log"
 	"log"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
+	"path"
 	"path/filepath"
 	"path/filepath"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -138,8 +139,10 @@ func InitV2DocRouter(docHTML string, docYAML string) http.Handler {
 }
 }
 func InitFile() http.Handler {
 func InitFile() http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 	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)
 	})
 	})
 }
 }