From 630dbc327eaba5dfd37f9bdbed532d6faffb1f62 Mon Sep 17 00:00:00 2001 From: ZZF <31278216+byxiaozhi@users.noreply.github.com> Date: Fri, 29 May 2020 21:37:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Region?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/policy.go | 3 +++ pkg/filesystem/driver/s3/handler.go | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/models/policy.go b/models/policy.go index 67ad4f0..e9aec07 100644 --- a/models/policy.go +++ b/models/policy.go @@ -49,6 +49,9 @@ type PolicyOption struct { // OdRedirect Onedrive重定向地址 OdRedirect string `json:"od_redirect,omitempty"` + + // Region 区域代码 + Region string `json:"region"` } var thumbSuffix = map[string][]string{ diff --git a/pkg/filesystem/driver/s3/handler.go b/pkg/filesystem/driver/s3/handler.go index 74e201c..429cdd7 100644 --- a/pkg/filesystem/driver/s3/handler.go +++ b/pkg/filesystem/driver/s3/handler.go @@ -59,7 +59,7 @@ func (handler *Driver) InitS3Client() error { sess, err := session.NewSession(&aws.Config{ Credentials: credentials.NewStaticCredentials(handler.Policy.AccessKey, handler.Policy.SecretKey, ""), Endpoint: &handler.Policy.Server, - Region: aws.String(strings.Split(handler.Policy.Server, ".")[0]), //表没有这个字段 + Region: &handler.Policy.OptionsSerialized.Region, S3ForcePathStyle: aws.Bool(false), }) if err != nil { @@ -392,7 +392,7 @@ func (handler Driver) getUploadCredential(ctx context.Context, policy UploadPoli longDate := time.Now().UTC().Format("20060102T150405Z") shortDate := time.Now().UTC().Format("20060102") - credential := handler.Policy.AccessKey + "/" + shortDate + "/" + handler.Policy.Server + "/s3/aws4_request" + credential := handler.Policy.AccessKey + "/" + shortDate + "/" + handler.Policy.OptionsSerialized.Region + "/s3/aws4_request" policy.Conditions = append(policy.Conditions, map[string]string{"x-amz-credential": credential}) policy.Conditions = append(policy.Conditions, map[string]string{"x-amz-date": longDate}) @@ -405,7 +405,7 @@ func (handler Driver) getUploadCredential(ctx context.Context, policy UploadPoli //签名 signature := getHMAC([]byte("AWS4"+handler.Policy.SecretKey), []byte(shortDate)) - signature = getHMAC(signature, []byte(handler.Policy.Server)) + signature = getHMAC(signature, []byte(handler.Policy.OptionsSerialized.Region)) signature = getHMAC(signature, []byte("s3")) signature = getHMAC(signature, []byte("aws4_request")) signature = getHMAC(signature, []byte(policyEncoded))