-
Notifications
You must be signed in to change notification settings - Fork 2
/
s3.go
executable file
·35 lines (29 loc) · 834 Bytes
/
s3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package s3
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"os"
)
// https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/go/example_code/s3/s3_upload_object.go
func Upload(local_file_path string, remote_file_name string, bucketname string) error {
file, err := os.Open(local_file_path)
if err != nil {
return err
}
defer file.Close()
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-east-1")},
)
// http://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3manager/#NewUploader
uploader := s3manager.NewUploader(sess)
_, err = uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String(bucketname),
Key: aws.String(remote_file_name),
Body: file,
})
if err != nil {
return err
}
return nil
}