Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
golang s3 PutObject
package main
import (
"bytes"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
func main() {
bucket := aws.String("xxxxxxxxxxxxxx")
keyname := aws.String("test123.txt")
sess := session.Must(session.NewSession())
svc := s3.New(sess, &aws.Config{Region: aws.String("ap-northeast-1")})
params := &s3.PutObjectInput{
Bucket: bucket, // Required
Key: keyname, // Required
ACL: aws.String("bucket-owner-full-control"),
Body: bytes.NewReader([]byte("PAYLOAD")),
// CacheControl: aws.String("CacheControl"),
// ContentDisposition: aws.String("ContentDisposition"),
// ContentEncoding: aws.String("ContentEncoding"),
// ContentLanguage: aws.String("ContentLanguage"),
ContentLength: aws.Int64(7),
// ContentType: aws.String("ContentType"),
// Expires: aws.Time(time.Now()),
// GrantFullControl: aws.String("GrantFullControl"),
// GrantRead: aws.String("GrantRead"),
// GrantReadACP: aws.String("GrantReadACP"),
// GrantWriteACP: aws.String("GrantWriteACP"),
// RequestPayer: aws.String("RequestPayer"),
// SSECustomerAlgorithm: aws.String("SSECustomerAlgorithm"),
// SSECustomerKey: aws.String("SSECustomerKey"),
// SSECustomerKeyMD5: aws.String("SSECustomerKeyMD5"),
// SSEKMSKeyId: aws.String("SSEKMSKeyId"),
}
resp, err := svc.PutObject(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
fmt.Println(resp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.