我正在尝试使用预先签名的POST URL(使用boto3生成)将文件上传到s3。
这些是生成的预签名URL中的字段:
{"acl":"private",
"key":"4982bfe3-fae9-42a5-9502-4cc3fcd9ee87__swcli",
"x-amz-algorithm":
"AWS4-HMAC-SHA256",
"x-amz-credential":"AKIAICDC2ZVHRX25EYNQ/20180626/us-east-1/s3/aws4_request",
"x-amz-date":"20180626T014755Z",
"policy":"eyJleDE0NzU1WiJ9XX0=",
"x-amz signature":"f803ef38cbdd8a16"}
我正在使用此代码进行请求
x := make(map[string]string)
x["key"],_ = jsonparser.GetString(*fields,"key")
x["acl"],_ = jsonparser.GetString(*fields,"acl")
x["x-amz-algorithm"],_ = jsonparser.GetString(*fields,"x-amz-algorithm")
x["x-amz-credential"],_ = jsonparser.GetString(*fields,"x-amz-credential")
x["x-amz-date"],_ = jsonparser.GetString(*fields,"x-amz-date")
x["policy"],_ = jsonparser.GetString(*fields,"policy")
x["x-amz-signature"],_ = jsonparser.GetString(*fields,"x-amz-signature")
c := new(http.Client)
req := request.NewRequest(c)
req.Data = x
f, err := os.Open("filewriter.go")
if err!=nil{
fmt.Println("errored")
}
req.Files = []request.FileField{
request.FileField{"file", "filewriter.go", f},
}
resp, err := req.Post("http://btrads-78.s3.amazonaws.com")
fmt.Println((resp.Text()))`
并收到此错误:
Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.
我尝试尝试使用x中key
的不同顺序组合并使用不同的HTTP客户端,但是出现了相同的错误。我在做什么错了?