fix: stream file; dont put it all in memory

This commit is contained in:
Henrique Dias 2017-12-27 16:17:36 +00:00
parent 6bfe6a2ea7
commit 16b2dcb745

View File

@ -111,6 +111,17 @@ func downloadFileHandler(c *fm.Context, w http.ResponseWriter, r *http.Request)
w.Header().Set("Content-Disposition", `attachment; filename="`+c.File.Name+`"`) w.Header().Set("Content-Disposition", `attachment; filename="`+c.File.Name+`"`)
} }
http.ServeFile(w, r, c.File.Path) file, err := os.Open(c.File.Path)
defer file.Close()
if err != nil {
return http.StatusInternalServerError, err
}
_, err = io.Copy(w, file)
if err != nil {
return http.StatusInternalServerError, err
}
return 0, nil return 0, nil
} }