Skip to content

Instantly share code, notes, and snippets.

@wangkuiyi
Created February 3, 2016 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wangkuiyi/a6ac56c2fc6d37e037be to your computer and use it in GitHub Desktop.
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.
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