diff --git a/config/config.yaml b/config/config.yaml index 2135f2135..f31368e98 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -59,14 +59,14 @@ api: listenIP: #默认为0.0.0.0 object: - enable: minio #使用minio - apiURL: http://127.0.0.1:10002/object/ + enable: "minio" #使用minio + apiURL: "http://127.0.0.1:10002/object/" minio: bucket: "openim" #不建议修改 - endpoint: http://127.0.0.1:10005 #minio对外服务的ip和端口,app要能访问此ip和端口 - accessKeyID: root #ID - secretAccessKey: openIM123 #秘钥 - sessionToken: #token + endpoint: "http://127.0.0.1:10005" #minio对外服务的ip和端口,app要能访问此ip和端口 + accessKeyID: "root" #ID + secretAccessKey: "openIM123" #秘钥 + sessionToken: "" #token cos: #tencent cos bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" secretID: "" diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index c9dd2860a..75f7b7f54 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -110,7 +110,7 @@ type config struct { SecretID string `yaml:"secretID"` SecretKey string `yaml:"secretKey"` SessionToken string `yaml:"sessionToken"` - } `yaml:"tencent"` + } `yaml:"cos"` Oss struct { Endpoint string `yaml:"endpoint"` Bucket string `yaml:"bucket"` @@ -118,7 +118,7 @@ type config struct { AccessKeyID string `yaml:"accessKeyID"` AccessKeySecret string `yaml:"accessKeySecret"` SessionToken string `yaml:"sessionToken"` - } `yaml:"ali"` + } `yaml:"oss"` } `yaml:"object"` RpcPort struct { diff --git a/pkg/common/db/s3/cos/cos.go b/pkg/common/db/s3/cos/cos.go index 8536613be..ed4a48676 100644 --- a/pkg/common/db/s3/cos/cos.go +++ b/pkg/common/db/s3/cos/cos.go @@ -33,17 +33,23 @@ func NewCos() (s3.Interface, error) { SessionToken: conf.SessionToken, }, }) + statObjectURL := u.String() + if statObjectURL != "" && statObjectURL[len(statObjectURL)-1] != '/' { + statObjectURL += "/" + } return &Cos{ - copyURL: u.Host + "/", - client: client, - credential: client.GetCredential(), + statObjectURL: statObjectURL, + copyURL: u.Host + "/", + client: client, + credential: client.GetCredential(), }, nil } type Cos struct { - copyURL string - client *cos.Client - credential *cos.Credential + statObjectURL string + copyURL string + client *cos.Client + credential *cos.Credential } func (c *Cos) Engine() string { @@ -59,6 +65,7 @@ func (c *Cos) PartLimit() *s3.PartLimit { } func (c *Cos) InitiateMultipartUpload(ctx context.Context, name string) (*s3.InitiateMultipartUploadResult, error) { + name = c.client.BaseURL.BucketURL.String() + name result, _, err := c.client.Object.InitiateMultipartUpload(ctx, name, nil) if err != nil { return nil, err @@ -166,7 +173,10 @@ func (c *Cos) DeleteObject(ctx context.Context, name string) error { } func (c *Cos) StatObject(ctx context.Context, name string) (*s3.ObjectInfo, error) { - info, err := c.client.Object.Head(ctx, name, nil) + if name != "" && name[0] == '/' { + name = name[1:] + } + info, err := c.client.Object.Head(ctx, c.statObjectURL+name, nil) if err != nil { return nil, err }