mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-17 21:08:25 +08:00
fix: Improve error handling in file download API (#11127)
This commit is contained in:
parent
997b820a42
commit
508ac2ae84
1 changed files with 6 additions and 1 deletions
|
|
@ -525,9 +525,14 @@ func (b *BaseApi) Download(c *gin.Context) {
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.InternalServer(c, err)
|
helper.InternalServer(c, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
info, _ := file.Stat()
|
info, err := file.Stat()
|
||||||
|
if err != nil {
|
||||||
|
helper.InternalServer(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
c.Header("Content-Length", strconv.FormatInt(info.Size(), 10))
|
c.Header("Content-Length", strconv.FormatInt(info.Size(), 10))
|
||||||
c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name()))
|
c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name()))
|
||||||
http.ServeContent(c.Writer, c.Request, info.Name(), info.ModTime(), file)
|
http.ServeContent(c.Writer, c.Request, info.Name(), info.ModTime(), file)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue