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 +} diff --git a/datetime.go b/datetime.go index f79be07..436a169 100644 --- a/datetime.go +++ b/datetime.go @@ -124,6 +124,11 @@ func ConvertStringToTimeLayout_YYYY_MM_DD_HH_MM_SS(date time.Time) string { return date.Format(LAYOUT_YYYY_MM_DD_HH_MM_SS) } +func ConvertToTimeLayout_YYYY_MM_DD_HH_MM_SS(value string) time.Time { + t, _ := time.Parse(LAYOUT_YYYY_MM_DD_HH_MM_SS, value) + return t +} + /* ConvertStringToTimeLayout_YYYY_MM_DD o antigo nome era: ConvertStringToTimeLAYOUT_YYYY_MM_DD */