How do I get the list of objects from a sub folder of an Amazon S3 bucket using golang?
I tried:
svc := s3.New(session.New(), &aws.Config{Region: aws.String("us-east-1")})
params := &s3.ListObjectsInput{
Bucket: aws.String("bucket"),
}
resp, _ := svc.ListObjects(params)
for _, key := range resp.Contents {
fmt.Println(*key.Key)
}
I got the list of all the objects in the bucket, but I need only the list of objects in a subfolder.
Add Prefix parameter in params
params := &s3.ListObjectsInput {
Bucket: aws.String("bucket"),
Prefix: aws.String("root/subfolder"),
}
will list objects from subfolder/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With