From 2b27e12445ba51e1fa1ab2aceac5fcb3de66845d Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Thu, 10 May 2018 18:16:33 -0400 Subject: MM-10188: expect io.Reader in FileBackend.WriteFile (#8765) This is a reworked set of changes originally from @josephGuo to begin reducing the duplicated memory required when uploading files. --- app/file.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'app/file.go') diff --git a/app/file.go b/app/file.go index 87e1986a2..cb8d54cb1 100644 --- a/app/file.go +++ b/app/file.go @@ -78,12 +78,13 @@ func (a *App) MoveFile(oldPath, newPath string) *model.AppError { return backend.MoveFile(oldPath, newPath) } -func (a *App) WriteFile(f []byte, path string) *model.AppError { +func (a *App) WriteFile(fr io.Reader, path string) (int64, *model.AppError) { backend, err := a.FileBackend() if err != nil { - return err + return 0, err } - return backend.WriteFile(f, path) + + return backend.WriteFile(fr, path) } func (a *App) RemoveFile(path string) *model.AppError { @@ -414,7 +415,7 @@ func (a *App) DoUploadFile(now time.Time, rawTeamId string, rawChannelId string, info.ThumbnailPath = pathPrefix + nameWithoutExtension + "_thumb.jpg" } - if err := a.WriteFile(data, info.Path); err != nil { + if _, err := a.WriteFile(bytes.NewReader(data), info.Path); err != nil { return nil, err } @@ -531,7 +532,7 @@ func (a *App) generateThumbnailImage(img image.Image, thumbnailPath string, widt return } - if err := a.WriteFile(buf.Bytes(), thumbnailPath); err != nil { + if _, err := a.WriteFile(buf, thumbnailPath); err != nil { mlog.Error(fmt.Sprintf("Unable to upload thumbnail path=%v err=%v", thumbnailPath, err)) return } @@ -553,7 +554,7 @@ func (a *App) generatePreviewImage(img image.Image, previewPath string, width in return } - if err := a.WriteFile(buf.Bytes(), previewPath); err != nil { + if _, err := a.WriteFile(buf, previewPath); err != nil { mlog.Error(fmt.Sprintf("Unable to upload preview err=%v", err), mlog.String("path", previewPath)) return } -- cgit v1.2.3-1-g7c22