summaryrefslogtreecommitdiffstats
path: root/app/file.go
diff options
context:
space:
mode:
authorJesse Hallam <jesse.hallam@gmail.com>2018-05-10 18:16:33 -0400
committerChristopher Speller <crspeller@gmail.com>2018-05-10 15:16:33 -0700
commit2b27e12445ba51e1fa1ab2aceac5fcb3de66845d (patch)
tree3d3bf61a39534e8db4cffde9b9644c3ce895580c /app/file.go
parent7fa1c6c4bae19d1647d759198126ee4591282079 (diff)
downloadchat-2b27e12445ba51e1fa1ab2aceac5fcb3de66845d.tar.gz
chat-2b27e12445ba51e1fa1ab2aceac5fcb3de66845d.tar.bz2
chat-2b27e12445ba51e1fa1ab2aceac5fcb3de66845d.zip
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.
Diffstat (limited to 'app/file.go')
-rw-r--r--app/file.go13
1 files changed, 7 insertions, 6 deletions
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
}