@@ -13,7 +13,7 @@ import (
1313 log "github.com/sirupsen/logrus"
1414)
1515
16- func (s3Ctrl * S3Controller ) FetchObjectContent (bucket string , key string ) ([] byte , error ) {
16+ func (s3Ctrl * S3Controller ) FetchObjectContent (bucket string , key string ) (io. ReadCloser , error ) {
1717 keyExist , err := s3Ctrl .KeyExists (bucket , key )
1818 if err != nil {
1919 return nil , err
@@ -30,12 +30,7 @@ func (s3Ctrl *S3Controller) FetchObjectContent(bucket string, key string) ([]byt
3030 return nil , err
3131 }
3232
33- body , err := io .ReadAll (output .Body )
34- if err != nil {
35- return nil , err
36- }
37-
38- return body , nil
33+ return output .Body , nil
3934}
4035
4136func (bh * BlobHandler ) HandleObjectContents (c echo.Context ) error {
@@ -54,7 +49,7 @@ func (bh *BlobHandler) HandleObjectContents(c echo.Context) error {
5449 return c .JSON (http .StatusUnprocessableEntity , errMsg .Error ())
5550 }
5651
57- body , err := s3Ctrl .FetchObjectContent (bucket , key )
52+ outPutBody , err := s3Ctrl .FetchObjectContent (bucket , key )
5853 if err != nil {
5954 log .Error ("HandleObjectContents: " + err .Error ())
6055 if strings .Contains (err .Error (), "object" ) {
@@ -63,7 +58,10 @@ func (bh *BlobHandler) HandleObjectContents(c echo.Context) error {
6358 return c .JSON (http .StatusInternalServerError , err .Error ())
6459 }
6560 }
66-
61+ body , err := io .ReadAll (outPutBody )
62+ if err != nil {
63+ return c .JSON (http .StatusInternalServerError , err .Error ())
64+ }
6765 log .Info ("HandleObjectContents: Successfully fetched object data for key:" , key )
6866 //TODO: add contentType
6967 return c .Blob (http .StatusOK , "" , body )
0 commit comments