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.
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
7fa1c6c4ba
Коммит
2b27e12445
@@ -98,7 +98,7 @@ func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *mode
|
||||
if err := gif.EncodeAll(newbuf, resized_gif); err != nil {
|
||||
return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.gif_encode_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
if err := a.WriteFile(newbuf.Bytes(), getEmojiImagePath(id)); err != nil {
|
||||
if _, err := a.WriteFile(newbuf, getEmojiImagePath(id)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -110,14 +110,15 @@ func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *mode
|
||||
if err := png.Encode(newbuf, resized_image); err != nil {
|
||||
return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.encode_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
if err := a.WriteFile(newbuf.Bytes(), getEmojiImagePath(id)); err != nil {
|
||||
if _, err := a.WriteFile(newbuf, getEmojiImagePath(id)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return a.WriteFile(buf.Bytes(), getEmojiImagePath(id))
|
||||
_, appErr := a.WriteFile(buf, getEmojiImagePath(id))
|
||||
return appErr
|
||||
}
|
||||
|
||||
func (a *App) DeleteEmoji(emoji *model.Emoji) *model.AppError {
|
||||
|
||||
13
app/file.go
13
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
|
||||
}
|
||||
|
||||
@@ -1001,7 +1001,7 @@ func (a *App) SetTeamIconFromFile(teamId string, file multipart.File) *model.App
|
||||
|
||||
path := "teams/" + teamId + "/teamIcon.png"
|
||||
|
||||
if err := a.WriteFile(buf.Bytes(), path); err != nil {
|
||||
if _, err := a.WriteFile(buf, path); err != nil {
|
||||
return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.write_file.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
@@ -754,7 +754,7 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
||||
}
|
||||
|
||||
if user.LastPictureUpdate == 0 {
|
||||
if err := a.WriteFile(img, path); err != nil {
|
||||
if _, err := a.WriteFile(bytes.NewReader(img), path); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
@@ -810,7 +810,7 @@ func (a *App) SetProfileImageFromFile(userId string, file multipart.File) *model
|
||||
|
||||
path := "users/" + userId + "/profile.png"
|
||||
|
||||
if err := a.WriteFile(buf.Bytes(), path); err != nil {
|
||||
if _, err := a.WriteFile(buf, path); err != nil {
|
||||
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.upload_profile.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user