Skip to content

Commit

Permalink
Fix the download file name error problem (IceWhaleTech#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong authored Feb 15, 2023
1 parent 1a2f917 commit 46e146e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions route/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"
"net/http"
"net/url"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
})
}

Expand Down

0 comments on commit 46e146e

Please sign in to comment.