s3 presigned test

test-v3dev1
withchao 1 year ago
parent 70b6cd360d
commit 5a9ecbf295

@ -5,4 +5,5 @@ const (
tempPath = "openim/temp/" tempPath = "openim/temp/"
UploadTypeMultipart = 1 // 分片上传 UploadTypeMultipart = 1 // 分片上传
UploadTypePresigned = 2 // 预签名上传 UploadTypePresigned = 2 // 预签名上传
partSeparator = ","
) )

@ -7,6 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/google/uuid" "github.com/google/uuid"
"path" "path"
"strings" "strings"
@ -143,7 +144,7 @@ func (c *Controller) CompleteUpload(ctx context.Context, uploadID string, partHa
if err != nil { if err != nil {
return nil, err return nil, err
} }
if md5Sum := md5.Sum([]byte(strings.Join(partHashs, ","))); hex.EncodeToString(md5Sum[:]) != upload.Hash { if md5Sum := md5.Sum([]byte(strings.Join(partHashs, partSeparator))); hex.EncodeToString(md5Sum[:]) != upload.Hash {
fmt.Println("CompleteUpload sum:", hex.EncodeToString(md5Sum[:]), "upload hash:", upload.Hash) fmt.Println("CompleteUpload sum:", hex.EncodeToString(md5Sum[:]), "upload hash:", upload.Hash)
return nil, errors.New("md5 mismatching") return nil, errors.New("md5 mismatching")
} }
@ -187,8 +188,9 @@ func (c *Controller) CompleteUpload(ctx context.Context, uploadID string, partHa
if uploadInfo.Size != upload.Size { if uploadInfo.Size != upload.Size {
return nil, errors.New("upload size mismatching") return nil, errors.New("upload size mismatching")
} }
md5Sum := md5.Sum([]byte(strings.Join([]string{uploadInfo.ETag}, ","))) md5Sum := md5.Sum([]byte(strings.Join([]string{uploadInfo.ETag}, partSeparator)))
if hex.EncodeToString(md5Sum[:]) != upload.Hash { if md5val := hex.EncodeToString(md5Sum[:]); md5val != upload.Hash {
log.ZInfo(ctx, "CompleteUpload UploadTypePresigned", "getEtag", uploadInfo.ETag, "upload", upload, "etag[]", md5val, "upload hash:", upload.Hash, "key:", upload.Key)
return nil, errors.New("upload md5 mismatching") return nil, errors.New("upload md5 mismatching")
} }
// 防止在这个时候,并发操作,导致文件被覆盖 // 防止在这个时候,并发操作,导致文件被覆盖

Loading…
Cancel
Save