Esempio n. 1
0
func ExampleCreate() {
	s3util.DefaultConfig.AccessKey = "...access key..."
	s3util.DefaultConfig.SecretKey = "...secret key..."
	r, _ := os.Open("/dev/stdin")
	w, _ := s3util.Create("https://mybucket.s3.amazonaws.com/log.txt", nil, nil)
	io.Copy(w, r)
	w.Close()
}
Esempio n. 2
0
// upload uploads a file to an s3 bucket.
func upload(bucket, file string, config *s3util.Config) error {
	// open the local file to upload
	localFile, err := os.Open(file)
	if err != nil {
		return err
	}
	defer localFile.Close()

	headers := http.Header{}
	headers.Add("x-amz-acl", "private")
	s3File, err := s3util.Create(generateS3Url(bucket, filepath.Base(file)), headers, config)
	if err != nil {
		return err
	}
	defer s3File.Close()

	// copy the file
	_, err = io.Copy(s3File, localFile)
	return err
}