Example #1
0
func PutInBucket(file string, remoteName string) (string, error) {
	var (
		_AWS_SECRET   string
		_AWS_ACCESS   string
		_AWS_LOCATION string
	)

	f, err := os.Open(file)

	_AWS_SECRET = os.Getenv("AWS_SECRET")
	_AWS_ACCESS = os.Getenv("AWS_ACCESS")
	_AWS_LOCATION = os.Getenv("AWS_LOCATION")

	if nil != err {
		return "", err
	}
	defer f.Close()
	auth, err := aws.GetAuth(_AWS_ACCESS, _AWS_SECRET)
	s3conn := s3.New(auth, aws.EUWest)
	bucket := s3conn.Bucket(LOCALS_BUCKET)
	data, err := ioutil.ReadAll(f)
	if nil != err {
		return "", err
	}
	log.Println(" adding filepath " + remoteName)

	err = bucket.Put(remoteName, data, "image/jpeg", s3.PublicRead)
	if nil != err {
		return "", err
	}
	return _AWS_LOCATION + "/" + remoteName, nil
}
Example #2
0
func (s *S) TestGetAuthEnv(c *C) {
	os.Clearenv()
	os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
	os.Setenv("AWS_ACCESS_KEY_ID", "access")
	auth, err := aws.GetAuth("", "")
	c.Assert(err, IsNil)
	c.Assert(auth, Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}
Example #3
0
func (s *S) TestGetAuthStatic(c *C) {
	auth, err := aws.GetAuth("access", "secret")
	c.Assert(err, IsNil)
	c.Assert(auth, Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}