douque9815 2018-06-26 02:00
浏览 734

“存储桶POST必须包含一个名为'key'的字段”错误

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?

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置