Last active
January 19, 2021 19:25
-
-
Save umtkas/7c06e175900d023120ed877a527baacb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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