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 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘