douyun7718
2016-09-22 11:22
浏览 356
已采纳

如何使用golang从Amazon S3存储桶的子文件夹中获取对象列表?

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.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doumubi6784 2017-05-02 11:56
    已采纳

    Add Prefix parameter in params

    params := &s3.ListObjectsInput {
        Bucket: aws.String("bucket"),
        Prefix: aws.String("root/subfolder"),
    }
    

    will list objects from subfolder/

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题