我正在尝试为S3中的GET对象请求创建一个签名的URL。我有这段代码可以完美地将对象放到S3中,但是我似乎无法使它适用于GET。我使用此代码在URL上签名
//Create the signed url using the company id
func (user *User) signURLForUser(sess *session.Session) (*URLSign, error) {
svc := s3.New(sess)
svc.Config.Region = aws.String(os.Getenv("REGION"))
req, _ := svc.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String("bucket"),
Key: aws.String(user.CompanyID + "/" + user.FileRequest),
})
var urlSign URLSign
//urlSign.Size = *out.ContentLength
str, err := req.Presign(time.Minute * 60 * 24 * 5) //Expire in 5 days
if err != nil {
log.Println("Error signing URL Request")
return nil, err
}
urlSign.URL = str
return &urlSign, nil
}
但是当我尝试使用URL返回时,出现此错误:
<Error>
<Code>AuthorizationQueryParametersError</Code>
<Message>X-Amz-Algorithm only supports "AWS4-HMAC-SHA256"</Message>
<RequestId>9D7CFB14B195A260</RequestId>
<HostId>
Dgh+SqrHbrdKcbkCYrAj3nObLMAwS7k5+VR1zwC/8ZMS3S4++IAAEXXh3zMZ3CpOAyxX1Kc7Opg=
</HostId>
</Error>
我已经检查了IAM权限,它们是为GetObject设置的。我想不出我在做什么错。
编辑:这是URL的示例 当然: https://rsmachiner-user-code.s3.amazonaws.com/ / CFDMP_ServoGear.gcode?X-Amz-Algorithm = AWS4-HMAC-SHA256&X-Amz-Content-Sha256 = UNSIGNED-PAYLOAD&X-Amz-Credential = ASIAVEENPDKJRUDZKEVM%2F20180812%2Fus-east-1%2Fs AMZ-日期= 20180812T005443Z&X-AMZ-过期= 432000&X-AMZ-安全令牌= FQoGZXIvYXdzEBoaDIVdv9t408gWWi9vvSLjAaa0pZNA%2BXu83%2FFSyng4XvFdv5%2B7nRB%2FQydMLyi%2BBS84yXqwP6VYn7VlInw4ip1M0lkjHRXQf8OAvQLPrIl%2FQZoTe%2Fy3N6bqhLDOnFVJ3UZzYDQ4%2FbX%2Brc6mvVbkhRsQPiarKBuLYDiOD%2FNoSaItMwI9FsMDknw1qX0Pf%2BZ5La0GmanHrTt9YUI01cIUKJ40No5mKJIwcXw3%2F5QOpUc59rZ2zEzlWP9OXeEwWKp%2Bog5P0v7ABX1lRPsCx4HGEstKhw3ZWmJfQhAcAvhrjmXIMqGNKkaCI5L0ap23jf4GvPMGd4%2BcKIKKvtsF&X-Amz- SignedHeaders = host&X-Amz-Signature = 82dfb9b392b5e1ef44c7140259ad884e696b48f8094bdd2d223b8650ebdf59f7
答案 0 :(得分:0)
当您未正确指定算法时,会发生此类问题。对我而言,我使用的是以下网址:https://s3_endpoint?X-Amz-Algorithm=AWS4-HMAC-SHA256 \ u0026 回到我同样的错误。我用&替换了\ u0026,效果很好。