Skip to content

Commit

Permalink
Merge pull request #3 from rafaeleupinheiro/main
Browse files Browse the repository at this point in the history
create method UpdloadInS3Base64Byte in aws_s3
  • Loading branch information
armando-couto authored Dec 20, 2021
2 parents 90d7dce + d78b47e commit 2875124
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions aws_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,34 @@ func UpdloadInS3Base64(b64 string, path, fileName string) string {
CreateFileDayInfo(fmt.Sprint("Upload do Arquivo: ", up.UploadID))
return "https://" + myBucket + "." + "s3.amazonaws.com/" + fileName
}

func UpdloadInS3Base64Byte(b64 []byte, path, fileName string) string {
// The session the S3 Uploader will use
sess := ConnectAws()

fileName = fmt.Sprint(time.Now().Format(LAYOUT_YYYYMMDDHHMMSS), fileName)

// Caso tenha om PATH ai ele concatena
if path != "" {
fileName = fmt.Sprint(path, "/", fileName)
}

// Create an uploader with the session and default options
uploader := s3manager.NewUploader(sess)

myBucket := Godotenv("BUCKET_NAME")

//upload to the s3 bucket
up, err := uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String(myBucket),
ACL: aws.String("public-read"),
Key: aws.String(fileName),
Body: bytes.NewBuffer(b64),
})
if err != nil {
CreateFileDayError(err.Error())
return ""
}
CreateFileDayInfo(fmt.Sprint("Upload do Arquivo: ", up.UploadID))
return "https://" + myBucket + "." + "s3.amazonaws.com/" + fileName
}

0 comments on commit 2875124

Please sign in to comment.