Skip to content

Instantly share code, notes, and snippets.

Created July 16, 2022 02:07
What would you like to do?
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