From 9d6715a62c14b7ff7c0739397692cee938751f79 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:01:09 +0700 Subject: [PATCH 1/2] fix: file extension --- internal/object/object.service.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/object/object.service.go b/internal/object/object.service.go index 4cd6146..bf3d4b8 100644 --- a/internal/object/object.service.go +++ b/internal/object/object.service.go @@ -3,6 +3,8 @@ package object import ( "context" "fmt" + "path/filepath" + "strings" proto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/store/object/v1" "github.com/isd-sgcu/rpkm67-store/config" @@ -41,7 +43,11 @@ func (s *serviceImpl) Upload(_ context.Context, req *proto.UploadObjectRequest) return nil, status.Error(codes.Internal, constant.InternalServerErrorMessage) } - objectKey := req.Filename + "_" + randomString + ext := filepath.Ext(req.Filename) + filename := strings.TrimSuffix(req.Filename, ext) + objectKey := filename + "_" + randomString + ext + + fmt.Println("objectKey: ", objectKey) url, key, err := s.repo.Upload(req.Data, s.conf.BucketName, objectKey) if err != nil { From 31060d1e340b0b9b629b590d3b13738a21084aef Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:02:36 +0700 Subject: [PATCH 2/2] chore --- internal/object/object.service.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/object/object.service.go b/internal/object/object.service.go index bf3d4b8..d80f0b3 100644 --- a/internal/object/object.service.go +++ b/internal/object/object.service.go @@ -47,8 +47,6 @@ func (s *serviceImpl) Upload(_ context.Context, req *proto.UploadObjectRequest) filename := strings.TrimSuffix(req.Filename, ext) objectKey := filename + "_" + randomString + ext - fmt.Println("objectKey: ", objectKey) - url, key, err := s.repo.Upload(req.Data, s.conf.BucketName, objectKey) if err != nil { s.log.Named("Upload").Error("Upload: ", zap.Error(err))