Skip to content

Commit 41f81c9

Browse files
author
sjqzhang
committed
fix small file upload and download
1 parent 7a4610a commit 41f81c9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

server/fileserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ func (c *Server) BuildFileResult(fileInfo *FileInfo, r *http.Request) FileResult
821821
}
822822
fileResult.Url = downloadUrl
823823
if Config().DefaultDownload {
824-
fileResult.Url = fmt.Sprintf("%s?name=%s&download=1", downloadUrl, url.PathEscape(outname))
824+
fileResult.Url = fmt.Sprintf("%s?name=%s&download=1", downloadUrl, url.PathEscape(fileInfo.Name))
825825
}
826826
fileResult.Md5 = fileInfo.Md5
827827
fileResult.Path = "/" + p

server/http_download.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import (
1717

1818
func (c *Server) SetDownloadHeader(w http.ResponseWriter, r *http.Request) {
1919
w.Header().Set("Content-Type", "application/octet-stream")
20-
w.Header().Set("Content-Disposition", "attachment")
2120
if name, ok := r.URL.Query()["name"]; ok {
2221
if v, err := url.QueryUnescape(name[0]); err == nil {
23-
name[0] = v
22+
name[0] = c.TrimFileNameSpecialChar(v)
2423
}
2524
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", name[0]))
25+
} else {
26+
w.Header().Set("Content-Disposition", "attachment")
2627
}
2728
}
2829

0 commit comments

Comments
 (0)