Skip to content

Instantly share code, notes, and snippets.

@umtkas
Last active January 19, 2021 19:25
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 umtkas/7c06e175900d023120ed877a527baacb to your computer and use it in GitHub Desktop.
Save umtkas/7c06e175900d023120ed877a527baacb to your computer and use it in GitHub Desktop.
func DownloadFile(configuration configs.Configuration, objectKey string) string {
downloader := createS3Downloader(configuration)
// create a image file on /tmp directory
file, err := os.Create(configuration.LocalImageDirectory + "/" + filepath.Base(objectKey))
if err != nil {
exitErrorf("DownloadFile:::Unable to open file, %v", err)
}
defer file.Close()
// download from s3 bucket
numBytes, err := downloader.Download(file,
&s3.GetObjectInput{
Bucket: aws.String(configuration.Bucket),
Key: aws.String(objectKey),
})
if err != nil {
exitErrorf("Unable to download item %q, %v", objectKey, err)
}
fmt.Println("Downloaded", file.Name(), numBytes, "bytes")
return configuration.LocalImageDirectory + "/" + filepath.Base(objectKey)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment