summaryrefslogtreecommitdiffstats
path: root/utils/file_backend_s3.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/file_backend_s3.go')
-rw-r--r--utils/file_backend_s3.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/file_backend_s3.go b/utils/file_backend_s3.go
index a0c46e5d3..dedcb2797 100644
--- a/utils/file_backend_s3.go
+++ b/utils/file_backend_s3.go
@@ -111,6 +111,25 @@ func (b *S3FileBackend) ReadFile(path string) ([]byte, *model.AppError) {
}
}
+func (b *S3FileBackend) FileExists(path string) (bool, *model.AppError) {
+ s3Clnt, err := b.s3New()
+
+ if err != nil {
+ return false, model.NewAppError("FileExists", "api.file.file_exists.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
+ }
+ _, err = s3Clnt.StatObject(b.bucket, path, s3.StatObjectOptions{})
+
+ if err == nil {
+ return true, nil
+ }
+
+ if err.(s3.ErrorResponse).Code == "NoSuchKey" {
+ return false, nil
+ }
+
+ return false, model.NewAppError("FileExists", "api.file.file_exists.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
+}
+
func (b *S3FileBackend) CopyFile(oldPath, newPath string) *model.AppError {
s3Clnt, err := b.s3New()
if err != nil {