Skip to content

Commit

Permalink
fix small file upload and download
Browse files Browse the repository at this point in the history
  • Loading branch information
sjqzhang committed Sep 18, 2024
1 parent 7a4610a commit 41f81c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func (c *Server) BuildFileResult(fileInfo *FileInfo, r *http.Request) FileResult
}
fileResult.Url = downloadUrl
if Config().DefaultDownload {
fileResult.Url = fmt.Sprintf("%s?name=%s&download=1", downloadUrl, url.PathEscape(outname))
fileResult.Url = fmt.Sprintf("%s?name=%s&download=1", downloadUrl, url.PathEscape(fileInfo.Name))
}
fileResult.Md5 = fileInfo.Md5
fileResult.Path = "/" + p
Expand Down
5 changes: 3 additions & 2 deletions server/http_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (

func (c *Server) SetDownloadHeader(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment")
if name, ok := r.URL.Query()["name"]; ok {
if v, err := url.QueryUnescape(name[0]); err == nil {
name[0] = v
name[0] = c.TrimFileNameSpecialChar(v)
}
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", name[0]))
} else {
w.Header().Set("Content-Disposition", "attachment")
}
}

Expand Down

0 comments on commit 41f81c9

Please sign in to comment.