Created
July 16, 2022 02:07
-
-
Save hernanhrm/45d528aebcd94089a68f5ad90371e438 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
const ( | |
// PublicRead is used to set the permission of a file to public read | |
PublicRead = "public-read" | |
// Private is used to set the permission of a file to private | |
Private = "private" | |
) | |
// Upload takes a file and uploads it to the s3 bucket | |
func (s Service) Upload(fileBytes []byte, contentType, path string, isPublic bool) error { | |
permission := PublicRead | |
if !isPublic { | |
permission = Private | |
} | |
_, err := s.S3.PutObject(&s3.PutObjectInput{ | |
Bucket: aws.String(s.Bucket), | |
Key: aws.String(path), | |
Body: bytes.NewReader(fileBytes), | |
ContentType: aws.String(contentType), | |
ACL: aws.String(permission), | |
}) | |
if err != nil { | |
return fmt.Errorf("s3.Upload(): %v", err) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment