Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/armando-couto/goutils into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
armando-couto committed Jan 11, 2022
2 parents 46ef285 + 2875124 commit db1b652
Show file tree
Hide file tree
Showing 2 changed files with 36 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
}
5 changes: 5 additions & 0 deletions datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit db1b652

Please sign in to comment.