From 4e33aeb5813fe50f6adad1b1dc35f5533cfd52af Mon Sep 17 00:00:00 2001 From: Jesse Haka Date: Mon, 10 Sep 2018 20:35:01 +0300 Subject: fix s3 memory usage (#9373) --- utils/file_backend_s3.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'utils/file_backend_s3.go') diff --git a/utils/file_backend_s3.go b/utils/file_backend_s3.go index 2868dd342..f5f96f878 100644 --- a/utils/file_backend_s3.go +++ b/utils/file_backend_s3.go @@ -4,6 +4,7 @@ package utils import ( + "bytes" "io" "io/ioutil" "net/http" @@ -182,7 +183,12 @@ func (b *S3FileBackend) WriteFile(fr io.Reader, path string) (int64, *model.AppE } options := s3PutOptions(b.encrypt, contentType) - written, err := s3Clnt.PutObject(b.bucket, path, fr, -1, options) + var buf bytes.Buffer + _, err = buf.ReadFrom(fr) + if err != nil { + return 0, model.NewAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError) + } + written, err := s3Clnt.PutObject(b.bucket, path, &buf, int64(buf.Len()), options) if err != nil { return written, model.NewAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError) } -- cgit v1.2.3-1-g7c22