From 140317e2dfffa006069132256f6a16b909604d7f Mon Sep 17 00:00:00 2001 From: ayflying Date: Wed, 11 Jun 2025 12:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=ADs3=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E5=95=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/s3/s3.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/s3/s3.go b/pkg/s3/s3.go index 81cdd43..62d5cea 100644 --- a/pkg/s3/s3.go +++ b/pkg/s3/s3.go @@ -31,6 +31,7 @@ type DataType struct { Url string `json:"url"` // S3 服务的访问 URL BucketName string `json:"bucket_name"` // 默认存储桶名称 BucketNameCdn string `json:"bucket_name_cdn"` // CDN 存储桶名称 + Provider string `json:"provider"` // S3 服务的提供方 } // Mod 定义了 S3 模块的结构体,包含一个 S3 客户端实例和配置信息 @@ -139,7 +140,7 @@ func (s *Mod) PutObject(f io.Reader, name string, bucketName string, _size ...in } // 调用 S3 客户端上传文件,设置内容类型为 "application/octet-stream" res, err = s.client.PutObject(ctx, bucketName, name, f, size, minio.PutObjectOptions{ - ContentType: "application/octet-stream", + //ContentType: "application/octet-stream", }) if err != nil { // 记录上传错误日志 @@ -191,9 +192,14 @@ func (s *Mod) GetUrl(filePath string, defaultFile ...string) (url string) { filePath = defaultFile[0] } - if s.cfg.Ssl { + switch s.cfg.Provider { + case "qiniu": + url = get + path.Join(bucketName, filePath) + default: url = get + filePath - } else { + } + + if !s.cfg.Ssl { url = get + path.Join(bucketName, filePath) }