从S3服务器返回以下响应:
<Error>
<Code>BucketAlreadyOwnedByYou</Code>
<Message>Your previous request to create the named bucket succeeded and you already own it.</Message>
<BucketName>newbucket</BucketName>
<Resource>/newbucket</Resource>
<RequestId>15C79B745D6D5C78</RequestId>
<HostId>1c8c1a3a-fe7a-472a-a401-b57d6997aa9e</HostId>
</Error>
出现错误时,如何通过使用
aws-sdk-go
从S3服务器获取xml响应?我想要所有的xml响应。func createBucket(s *s3.S3) {
out, err := s.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String("newbucket"),
})
}
在我的情况下仅使用
err
是不够的。谢谢您的时间。
最佳答案
我找到了方法:
head := s3.GetObjectInput{Bucket: &bucket, Key: aws.String("a")}
req, _ := fs.s3.GetObjectRequest(&head)
req.Handlers.UnmarshalMeta.PushBack(func(req *request.Request) {
defer req.HTTPResponse.Body.Close()
//req.HTTPResponse.Header['x-amz-bucket-region']
buf, err := ioutil.ReadAll(req.HTTPResponse.Body)
fmt.Printf("err: %v", string(buf))
return
})
req.Send()
有关更多详细信息,请访问https://github.com/aws/aws-sdk-go/issues/542#issuecomment-180893732。
关于go - 如何通过使用aws-sdk-go获取S3返回的xml格式错误响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58093007/