Fix the download file name error problem (#896)

This commit is contained in:
link 2023-02-15 17:31:20 +08:00 committed by GitHub
parent 1a2f917b30
commit 46e146e633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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") filePath := r.URL.Query().Get("path")
http.ServeFile(w, r, path) fileName := path.Base(filePath)
w.Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(fileName))
http.ServeFile(w, r, filePath)
}) })
} }