增加Region

This commit is contained in:
ZZF 2020-05-29 21:37:59 +08:00
parent 9fbbcfa568
commit 630dbc327e
2 changed files with 6 additions and 3 deletions

View file

@ -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{

View file

@ -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))