具有公共访问权限的AWS Go SDK S3上传

时间:2018-08-13 02:32:04

标签: go amazon-s3 aws-sdk

我一直试图通过公共访问将对象上载到S3,但是我无法做到这一点。

我收到此错误:InvalidArgument: Argument format not recognized status code: 400

这是我的代码:

bucketName := "test-bucket"
key2 := "test.zip"
upParams := &s3manager.UploadInput{
    Bucket: &bucketName,
    Key:    &key2,
    Body:   response.Body,
    GrantRead: aws.String("uri:http://acs.amazonaws.com/groups/global/AllUsers"),
}

sess := session.Must(session.NewSession())

uploader := s3manager.NewUploader(sess)

_, err = uploader.Upload(upParams)

1 个答案:

答案 0 :(得分:6)

尝试ACL:改为“公开阅读”

bucketName := "test-bucket"
key2 := "test.zip"
upParams := &s3manager.UploadInput{
    Bucket: &bucketName,
    Key:    &key2,
    Body:   response.Body,
    ACL: "public-read",
}

sess := session.Must(session.NewSession())

uploader := s3manager.NewUploader(sess)

_, err = uploader.Upload(upParams)