diff --git a/router/router_download.go b/router/router_download.go index 8ebcaa557..5edbfa5d8 100644 --- a/router/router_download.go +++ b/router/router_download.go @@ -4,7 +4,9 @@ import ( "bufio" "errors" "net/http" + "net/url" "os" + "path/filepath" "strconv" "github.com/gin-gonic/gin" @@ -81,6 +83,12 @@ func getDownloadFile(c *gin.Context) { return } + filePath, err := url.QueryUnescape(token.FilePath) + if err != nil { + middleware.CaptureAndAbort(c, err) + return + } + s, ok := manager.Get(token.ServerUuid) if !ok || !token.IsUniqueRequest() { c.AbortWithStatusJSON(http.StatusNotFound, gin.H{ @@ -89,7 +97,7 @@ func getDownloadFile(c *gin.Context) { return } - f, st, err := s.Filesystem().File(token.FilePath) + f, st, err := s.Filesystem().File(filePath) if err != nil { middleware.CaptureAndAbort(c, err) return @@ -103,7 +111,8 @@ func getDownloadFile(c *gin.Context) { } c.Header("Content-Length", strconv.Itoa(int(st.Size()))) - c.Header("Content-Disposition", "attachment; filename="+strconv.Quote(st.Name())) + filename := filepath.Base(filePath) + c.Header("Content-Disposition", "attachment; filename="+strconv.Quote(filename)) c.Header("Content-Type", "application/octet-stream") _, _ = bufio.NewReader(f).WriteTo(c.Writer)