diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/file_backend.go | 1 | ||||
-rw-r--r-- | utils/file_backend_local.go | 8 | ||||
-rw-r--r-- | utils/file_backend_s3.go | 12 |
3 files changed, 21 insertions, 0 deletions
diff --git a/utils/file_backend.go b/utils/file_backend.go index 60c90960d..9ed564592 100644 --- a/utils/file_backend.go +++ b/utils/file_backend.go @@ -13,6 +13,7 @@ import ( type FileBackend interface { TestConnection() *model.AppError + Reader(path string) (io.ReadCloser, *model.AppError) ReadFile(path string) ([]byte, *model.AppError) CopyFile(oldPath, newPath string) *model.AppError MoveFile(oldPath, newPath string) *model.AppError diff --git a/utils/file_backend_local.go b/utils/file_backend_local.go index a2d311f83..ec0c657a7 100644 --- a/utils/file_backend_local.go +++ b/utils/file_backend_local.go @@ -33,6 +33,14 @@ func (b *LocalFileBackend) TestConnection() *model.AppError { return nil } +func (b *LocalFileBackend) Reader(path string) (io.ReadCloser, *model.AppError) { + if f, err := os.Open(filepath.Join(b.directory, path)); err != nil { + return nil, model.NewAppError("Reader", "api.file.reader.reading_local.app_error", nil, err.Error(), http.StatusInternalServerError) + } else { + return f, nil + } +} + func (b *LocalFileBackend) ReadFile(path string) ([]byte, *model.AppError) { if f, err := ioutil.ReadFile(filepath.Join(b.directory, path)); err != nil { return nil, model.NewAppError("ReadFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusInternalServerError) diff --git a/utils/file_backend_s3.go b/utils/file_backend_s3.go index 6f1fa9ab0..a0c46e5d3 100644 --- a/utils/file_backend_s3.go +++ b/utils/file_backend_s3.go @@ -82,6 +82,18 @@ func (b *S3FileBackend) TestConnection() *model.AppError { return nil } +func (b *S3FileBackend) Reader(path string) (io.ReadCloser, *model.AppError) { + s3Clnt, err := b.s3New() + if err != nil { + return nil, model.NewAppError("Reader", "api.file.reader.s3.app_error", nil, err.Error(), http.StatusInternalServerError) + } + minioObject, err := s3Clnt.GetObject(b.bucket, path, s3.GetObjectOptions{}) + if err != nil { + return nil, model.NewAppError("Reader", "api.file.reader.s3.app_error", nil, err.Error(), http.StatusInternalServerError) + } + return minioObject, nil +} + func (b *S3FileBackend) ReadFile(path string) ([]byte, *model.AppError) { s3Clnt, err := b.s3New() if err != nil { |