java 使用带通配符的 S3 AmazonS3Client listObjects 前缀?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16220954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:16:25  来源:igfitidea点击:

Use S3 AmazonS3Client listObjects prefix with wildcard?

javaamazon-web-servicesamazon-s3

提问by mlabour

Does the AWS S3 AmazonS3Client.listObjects (http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html) support wildcard? for example, can one do the following:

AWS S3 AmazonS3Client.listObjects ( http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html) 是否支持通配符?例如,可以执行以下操作:

ListObjectsRequest listObjectsRequest = new ListObjectsRequest().
withBucketName("foo").
withPrefix("*/dt=2013-03-28/*").
withDelimiter("/");

回答by Viccari

No, you cannot. In fact, *is a valid character in a key name in S3. For example, a key like /foo/b*ar/dt=2013-03-28/abc.xmlis valid.
You will either need to reorganize your keys according to a common prefix or iterate over them all.

你不能。实际上,*是 S3 中键名中的有效字符。例如,像这样的键/foo/b*ar/dt=2013-03-28/abc.xml是有效的。
您要么需要根据公共前缀重新组织您的密钥,要么需要遍历所有密钥。

PS: depending on your use case, it is possible that you can use a marker.

PS:根据您的用例,您可以使用marker.