增加Region

pull/425/head
ZZF 5 years ago
parent 9fbbcfa568
commit 630dbc327e

@ -49,6 +49,9 @@ type PolicyOption struct {
// OdRedirect Onedrive重定向地址 // OdRedirect Onedrive重定向地址
OdRedirect string `json:"od_redirect,omitempty"` OdRedirect string `json:"od_redirect,omitempty"`
// Region 区域代码
Region string `json:"region"`
} }
var thumbSuffix = map[string][]string{ var thumbSuffix = map[string][]string{

@ -59,7 +59,7 @@ func (handler *Driver) InitS3Client() error {
sess, err := session.NewSession(&aws.Config{ sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials(handler.Policy.AccessKey, handler.Policy.SecretKey, ""), Credentials: credentials.NewStaticCredentials(handler.Policy.AccessKey, handler.Policy.SecretKey, ""),
Endpoint: &handler.Policy.Server, Endpoint: &handler.Policy.Server,
Region: aws.String(strings.Split(handler.Policy.Server, ".")[0]), //表没有这个字段 Region: &handler.Policy.OptionsSerialized.Region,
S3ForcePathStyle: aws.Bool(false), S3ForcePathStyle: aws.Bool(false),
}) })
if err != nil { if err != nil {
@ -392,7 +392,7 @@ func (handler Driver) getUploadCredential(ctx context.Context, policy UploadPoli
longDate := time.Now().UTC().Format("20060102T150405Z") longDate := time.Now().UTC().Format("20060102T150405Z")
shortDate := time.Now().UTC().Format("20060102") 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-credential": credential})
policy.Conditions = append(policy.Conditions, map[string]string{"x-amz-date": longDate}) 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([]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("s3"))
signature = getHMAC(signature, []byte("aws4_request")) signature = getHMAC(signature, []byte("aws4_request"))
signature = getHMAC(signature, []byte(policyEncoded)) signature = getHMAC(signature, []byte(policyEncoded))

Loading…
Cancel
Save