I need to upload a file to my S3 Bucket, inside a specific directory. I've used the aws-sdk-go package and was able to upload the file using PutObject
function inside my bucket. The file will be located in bucket/root
directory.
What I need to do is to upload it inside bucket/root/subDirectory
and I'm not able to figure that one out.
Current Upload Function
_, s3Err := s3.New(s).PutObject(&s3.PutObjectInput{
Bucket: aws.String(envs.InitAWSEnvs().AWSS3Name),
Key: aws.String(fileDir),
ACL: aws.String("private"),
Body: bytes.NewReader(buffer),
ContentLength: aws.Int64(size),
ContentType: aws.String(http.DetectContentType(buffer)),
ContentDisposition: aws.String("attachment"),
ServerSideEncryption: aws.String("AES256"),
})
I figured out a not-so-common gem that might be useful to a lot of people, the path.Join
function.
So mainly, the Key
object of PutObjectInput
parameter inside PutObject
function call will have a value of aws.String(path.Join(path_to_directory, fileName)
instead of aws.String(fileName)