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

“存储桶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 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥85 maple软件,solve求反函数,出现rootof怎么办?
    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题