-1

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"),
    })
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
TheLebDev
  • 531
  • 6
  • 18
  • What do you mean by "I'm not able to figure that one out"? This is not a useful problem description. What exact problem are you facing? – Jonathan Hall Jul 22 '19 at 08:49
  • Does this answer your question? [How to upload files to a Amazon S3 bucket subfolder via POST?](https://stackoverflow.com/questions/5512523/how-to-upload-files-to-a-amazon-s3-bucket-subfolder-via-post) – Yoav Feuerstein Aug 03 '21 at 12:20

1 Answers1

0

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)

TheLebDev
  • 531
  • 6
  • 18