fix():修改s3为阿里云oss
This commit is contained in:
@@ -39,7 +39,18 @@ func initClient() error {
|
||||
Credentials: credentials.NewStaticCredentialsProvider(cfg.AccessKeyID, cfg.AccessKeySecret, ""),
|
||||
}
|
||||
|
||||
s3c := s3.NewFromConfig(awsCfg)
|
||||
// 如果配置了自定义 endpoint (如阿里云 OSS),则设置 endpoint resolver
|
||||
if cfg.Endpoint != "" {
|
||||
awsCfg.BaseEndpoint = aws.String("https://" + cfg.Endpoint)
|
||||
}
|
||||
|
||||
// 创建 S3 客户端,使用虚拟主机样式(阿里云 OSS 要求)
|
||||
s3c := s3.NewFromConfig(awsCfg, func(o *s3.Options) {
|
||||
// 阿里云 OSS 使用虚拟主机样式: bucket.endpoint/key
|
||||
// AWS S3 默认也是虚拟主机样式,所以保持 UsePathStyle = false (默认值)
|
||||
o.UsePathStyle = false
|
||||
})
|
||||
|
||||
c = &s3Client{
|
||||
client: s3c,
|
||||
presign: s3.NewPresignClient(s3c),
|
||||
|
||||
Reference in New Issue
Block a user