From 08de5efeb4a502ac2dfafb85660e73750cb3088a Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 27 Dec 2017 16:18:27 +0000 Subject: [PATCH] fix: stream file instead of putting it all in memory (#303) Former-commit-id: 2dc1092f4111870eda6fd51f06cf6dadcac27c78 [formerly 6b21e8ca91b69a70aa07a60099e6919cf1f29fff] [formerly 5860c903ca50aa9a29f91c98d144e859fa223977 [formerly e6a8e3349e36d8439942228b75c2824407dfcb5c]] Former-commit-id: f8923f5d3fa5d638170ccd870ed4d38abee42d2e [formerly 1a1b27bb606ea012bb5eb3ee42ab6f1d585e1490] Former-commit-id: f7a238d6ed3e61b925fa20e7ecca145b1f903dba --- http/download.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/http/download.go b/http/download.go index 0b8666eb..5ec116a2 100644 --- a/http/download.go +++ b/http/download.go @@ -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 }