使用 aws-sdk-go 将文件保存到 S3

我在使用 AWS S3 go sdk ( https://github.com/awslabs/aws-sdk-go )在 golang 中保存文件时遇到了一些麻烦。


这就是我所拥有的:


import (

        "fmt"

        "bytes"


        "github.com/awslabs/aws-sdk-go/aws"

        "github.com/awslabs/aws-sdk-go/aws/awsutil"

        "github.com/awslabs/aws-sdk-go/service/s3"

)


func main() {    

    cred := aws.DefaultChainCredentials

    cred.Get() // i'm using environment variable credentials and yes, I checked if they were in here

    svc := s3.New(&aws.Config{Region: "us-west-2", Credentials:cred, LogLevel: 1})

    params := &s3.PutObjectInput{

                    Bucket:         aws.String("my-bucket-123"),

                    Key:            aws.String("test/123/"),

                    Body:         bytes.NewReader([]byte("testing!")),

            }

    resp, err := svc.PutObject(params)

    fmt.Printf("response %s", awsutil.StringValue(resp))

}

我不断收到301 Moved Permanently回复。


编辑:我手动创建了存储桶。编辑 #2:示例响应:


---[ RESPONSE ]--------------------------------------

HTTP/1.1 301 Moved Permanently

Transfer-Encoding: chunked

Content-Type: application/xml

Date: Tue, 05 May 2015 18:42:03 GMT

Server: AmazonS3

POST 标志也是 http。


狐的传说
浏览 340回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go