fix: stream file instead of putting it all in memory (#303)

Former-commit-id: 2dc1092f4111870eda6fd51f06cf6dadcac27c78 [formerly 6b21e8ca91b69a70aa07a60099e6919cf1f29fff] [formerly 5860c903ca50aa9a29f91c98d144e859fa223977 [formerly e6a8e3349e]]
Former-commit-id: f8923f5d3fa5d638170ccd870ed4d38abee42d2e [formerly 1a1b27bb606ea012bb5eb3ee42ab6f1d585e1490]
Former-commit-id: f7a238d6ed3e61b925fa20e7ecca145b1f903dba
pull/726/head
Henrique Dias 2017-12-27 16:18:27 +00:00 committed by GitHub
parent 74f690a71b
commit 08de5efeb4
1 changed files with 12 additions and 1 deletions

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+`"`)
}
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
}