From 77394313aa27c94cd47d4d95d79f4f5f686fda6c Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 11 Oct 2020 13:05:14 +0800 Subject: [PATCH] Fix: S3 adaption for minio --- assets | 2 +- models/policy.go | 15 ++++++++++++--- pkg/filesystem/driver/s3/handler.go | 1 + routers/controllers/callback.go | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/assets b/assets index 8f2a9c3..f342a2a 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 8f2a9c3d8138e5726fa841d239ca3a2bd946dc1b +Subproject commit f342a2a7774c5163f8d5a6760b556b69d6fe498f diff --git a/models/policy.go b/models/policy.go index e9aec07..f8255df 100644 --- a/models/policy.go +++ b/models/policy.go @@ -3,6 +3,7 @@ package model import ( "encoding/gob" "encoding/json" + "fmt" "net/url" "path" "path/filepath" @@ -239,7 +240,7 @@ func (policy *Policy) GetUploadURL() string { return policy.Server } - var controller *url.URL + controller, _ := url.Parse("") switch policy.Type { case "local", "onedrive": return "/api/v3/file/upload" @@ -251,9 +252,17 @@ func (policy *Policy) GetUploadURL() string { return policy.Server case "upyun": return "https://v0.api.upyun.com/" + policy.BucketName - default: - controller, _ = url.Parse("") + case "s3": + if policy.Server == "" { + return fmt.Sprintf("https://%s.s3.%s.amazonaws.com/", policy.BucketName, + policy.OptionsSerialized.Region) + } + + if !strings.Contains(policy.Server, policy.BucketName) { + controller, _ = url.Parse("/" + policy.BucketName) + } } + return server.ResolveReference(controller).String() } diff --git a/pkg/filesystem/driver/s3/handler.go b/pkg/filesystem/driver/s3/handler.go index 9283bac..9ebf951 100644 --- a/pkg/filesystem/driver/s3/handler.go +++ b/pkg/filesystem/driver/s3/handler.go @@ -62,6 +62,7 @@ func (handler *Driver) InitS3Client() error { Region: &handler.Policy.OptionsSerialized.Region, S3ForcePathStyle: aws.Bool(false), }) + if err != nil { return err } diff --git a/routers/controllers/callback.go b/routers/controllers/callback.go index 16d6e79..3d80d44 100644 --- a/routers/controllers/callback.go +++ b/routers/controllers/callback.go @@ -110,6 +110,7 @@ func COSCallback(c *gin.Context) { // S3Callback S3上传完成客户端回调 func S3Callback(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", "*") var callbackBody callback.S3Callback if err := c.ShouldBindQuery(&callbackBody); err == nil { res := callbackBody.PreProcess(c)