I am trying to upload a file to s3 using a presigned POST URL (generated using boto3).
These are the fields in the generated presigned 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"}
I am using this code to make the request
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()))`
And receiving this error:
Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.
I have tried trying different combinations of order of key
in x and using different HTTP client, but I am getting the same error. What am I doing wrong?