Created
February 3, 2016 19:19
-
-
Save wangkuiyi/a6ac56c2fc6d37e037be to your computer and use it in GitHub Desktop.
Shows how to use https://github.com/AdRoll/goamz/tree/master/s3 to access an AWS bucket created on AWS console.
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 ( | |
"bytes" | |
"image" | |
"image/jpeg" | |
"io" | |
"github.com/AdRoll/goamz/aws" | |
"github.com/AdRoll/goamz/s3" | |
. "github.com/topicai/candy" | |
) | |
var ( | |
integrationTesterAccessKey = // key | |
integrationTesterSecretKey = // secret key | |
integrationTesterRegion = aws.USWest2 | |
) | |
func main() { | |
var e error | |
srv := s3.New( | |
aws.Auth{ | |
AccessKey: integrationTesterAccessKey, | |
SecretKey: integrationTesterSecretKey}, | |
integrationTesterRegion) | |
bkt := srv.Bucket("yi-test-images") | |
im := WithOpened(TestData("s.jpg"), func(r io.Reader) interface{} { | |
im, _, e := image.Decode(r) | |
Must(e) | |
return im | |
}).(image.Image) | |
var buf bytes.Buffer | |
Must(jpeg.Encode(&buf, im, &jpeg.Options{Quality: 50})) | |
Must( | |
bkt.PutReader("s.jpg", &buf, int64(buf.Len()), | |
"image/jpeg", s3.PublicRead, s3.Options{})) | |
bts, e := bkt.Get("s.jpg") | |
Must(e) | |
im2, _, e := image.Decode(bytes.NewReader(bts)) | |
Must(e) | |
WithCreated(TestData("s2.jpg"), func(w io.Writer) { | |
Must(jpeg.Encode(w, im2, &jpeg.Options{Quality: 50})) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment