Fix: add filename when download file

This commit is contained in:
2022-04-18 02:09:57 +08:00
parent 6e9e7252b2
commit 544b5afc0d
2 changed files with 21 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"os"
"strconv"
)
@@ -111,6 +112,12 @@ func (api *API) HandleGetFileDirect(w http.ResponseWriter, r *http.Request) {
return
}
// set header for filename
filename := file.Filename
// encode filename to URL
filename = url.PathEscape(filename)
w.Header().Set("Content-Disposition", "inline; filename*=UTF-8''"+filename)
log.Println("[api] Get direct raw file", path)
http.ServeFile(w, r, path)