From 8e2301eb3453d324f7801569b3b6a13138b1c4d4 Mon Sep 17 00:00:00 2001 From: ayflying Date: Wed, 11 Jun 2025 11:02:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E4=BA=86=E5=85=BC=E5=AE=B9=E4=B8=83?= =?UTF-8?q?=E7=89=9B=E4=BA=91=E6=8E=A5=E5=8F=A3=EF=BC=8Cs3=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E4=BD=BF=E7=94=A8=E8=B7=AF=E5=BE=84=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/s3/s3.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/s3/s3.go b/pkg/s3/s3.go index 17e14e7..81cdd43 100644 --- a/pkg/s3/s3.go +++ b/pkg/s3/s3.go @@ -24,12 +24,12 @@ var ( // DataType 定义了 S3 配置的数据结构,用于存储访问 S3 所需的各种信息 type DataType struct { - AccessKey string `json:"access_key"` // 访问 S3 的密钥 ID - SecretKey string `json:"secret_key"` // 访问 S3 的密钥 - Address string `json:"address"` // S3 服务的地址 - Ssl bool `json:"ssl"` // 是否使用 SSL 加密连接 - Url string `json:"url"` // S3 服务的访问 URL - BucketName string `json:"bucket_name"` // 默认存储桶名称 + AccessKey string `json:"access_key"` // 访问 S3 的密钥 ID + SecretKey string `json:"secret_key"` // 访问 S3 的密钥 + Address string `json:"address"` // S3 服务的地址 + Ssl bool `json:"ssl"` // 是否使用 SSL 加密连接 + Url string `json:"url"` // S3 服务的访问 URL + BucketName string `json:"bucket_name"` // 默认存储桶名称 BucketNameCdn string `json:"bucket_name_cdn"` // CDN 存储桶名称 } @@ -62,8 +62,9 @@ func New(_name ...string) *Mod { obj, err := minio.New( cfg.Address, &minio.Options{ - Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""), - Secure: cfg.Ssl, + Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""), + Secure: cfg.Ssl, + BucketLookup: minio.BucketLookupPath, }, ) if err != nil { @@ -137,7 +138,9 @@ func (s *Mod) PutObject(f io.Reader, name string, bucketName string, _size ...in size = _size[0] } // 调用 S3 客户端上传文件,设置内容类型为 "application/octet-stream" - res, err = s.client.PutObject(ctx, bucketName, name, f, size, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + res, err = s.client.PutObject(ctx, bucketName, name, f, size, minio.PutObjectOptions{ + ContentType: "application/octet-stream", + }) if err != nil { // 记录上传错误日志 g.Log().Error(ctx, err) @@ -148,6 +151,7 @@ func (s *Mod) PutObject(f io.Reader, name string, bucketName string, _size ...in // RemoveObject 从指定存储桶中删除指定名称的文件 func (s *Mod) RemoveObject(name string, bucketName string) (err error) { opts := minio.RemoveObjectOptions{ + ForceDelete: true, //GovernanceBypass: true, //VersionID: "myversionid", }