Exemplo n.º 1
0
func ExampleOpen() {
	s3util.DefaultConfig.AccessKey = "...access key..."
	s3util.DefaultConfig.SecretKey = "...secret key..."
	r, _ := s3util.Open("https://mybucket.s3.amazonaws.com/log.txt", nil)
	w, _ := os.Create("out.txt")
	io.Copy(w, r)
	w.Close()
}
Exemplo n.º 2
0
// download downloads a file from an s3 bucket.
func download(bucket, sourceFile, destFile string, config *s3util.Config) error {
	headers := http.Header{}
	headers.Add("x-amz-acl", "private")
	s3File, err := s3util.Open(generateS3Url(bucket, sourceFile), config)
	if err != nil {
		return err
	}
	defer s3File.Close()

	// open the local file to download to
	localFile, err := os.Create(destFile)
	if err != nil {
		return err
	}
	defer localFile.Close()

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