Last active
June 5, 2019 10:13
-
-
Save isratmir/7d2f5dd8b1ac2efd0398c5744cb41b2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"time" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
) | |
func main() { | |
sess, err := session.NewSession( | |
&aws.Config{ | |
Region: aws.String("us-west-1"), | |
Credentials: credentials.NewSharedCredentials("", "staging")}) | |
if err != nil { | |
log.Println("error: ", err) | |
} | |
svc := s3.New(sess) | |
// download(svc) | |
filename := "/posts/uuid/slate_teacherly.png" | |
put(svc, filename) | |
} | |
func download(svc *s3.S3) { | |
req, _ := svc.GetObjectRequest(&s3.GetObjectInput{ | |
Bucket: aws.String("testrad-userfiles-mobilehub-519262803"), | |
Key: aws.String("public/example-image.png"), | |
}) | |
urlStr, err := req.Presign(15 * time.Minute) | |
if err != nil { | |
log.Println("Filed to sign request", err) | |
} | |
log.Println("The URL is:", urlStr) | |
} | |
func put(svc *s3.S3, filepath string) { | |
req, _ := svc.PutObjectRequest(&s3.PutObjectInput{ | |
Bucket: aws.String("seso-content-bucket"), | |
Key: aws.String(filepath), | |
}) | |
str, err := req.Presign(10 * time.Minute) | |
log.Println("The URL is:", str, " err:", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment