From d78b47e9f40c5e50520f78315ecf3743482a6599 Mon Sep 17 00:00:00 2001 From: Rafael Pinheiro Date: Mon, 20 Dec 2021 13:27:40 -0300 Subject: [PATCH] create method UpdloadInS3Base64Byte in aws_s3 --- aws_s3.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/aws_s3.go b/aws_s3.go index b92ace2..7a066d6 100644 --- a/aws_s3.go +++ b/aws_s3.go @@ -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 +}