[英]How To Filter, Pattern-Match Files on Retrieval from AWS S3 using .NET AWS SDK?
When using the ListObjects
request (.NET AWS SDK), is there a way to only list files where the key matches a given pattern?使用ListObjects
请求(.NET AWS SDK)时,有没有办法只列出键与给定模式匹配的文件? Or, more broadly, is there a way to query files from S3
based on their key using any request type from the .NET AWS SDK?或者,更广泛地说,有没有一种方法可以使用 .NET AWS 开发工具包中的任何请求类型根据密钥从S3
查询文件?
I'm aware of the --query
param, available on AWS CLI , but I'm not able to find an equivalent method on .NET.我知道AWS CLI 上可用的--query
参数,但我无法在 .NET 上找到等效的方法。
I'm looking for a way to run the query server-side so that ListObjects
returns a pattern-matching set of keys.我正在寻找一种运行查询服务器端的方法,以便ListObjects
返回一组模式匹配的键。 I'd like to avoid retrieving all files and then
filter them.我想避免检索所有文件and then
过滤它们。
The AWS CLI uses JMESPath for query expressions. AWS CLI 将JMESPath用于查询表达式。 There is a .NET port called JmesPath.NET that is compatible with the same API and is well-maintained.有一个名为JmesPath.NET的 .NET 端口,它与相同的 API 兼容并且维护良好。 You could use the SDK to retrieve the result set, and then filter it with JmesPath.NET expressions.您可以使用 SDK 来检索结果集,然后使用 JmesPath.NET 表达式对其进行过滤。 It's available as a NuGet package too.它也可以作为NuGet 包使用。
The --query
param on the CLI filters the result set on output, similar to what would happen with JmesPath.NET. CLI 上的--query
参数过滤输出的结果集,类似于 JmesPath.NET 会发生的情况。 It doesn't affect what the API call returns.它不会影响 API 调用返回的内容。 The only request parameters available to reduce the result set are prefix
and delimiter
, which group things logically like a folder structure does in a file storage engine.可用于减少结果集的唯一请求参数是prefix
和delimiter
,它们在逻辑上对事物进行分组,就像文件存储引擎中的文件夹结构一样。 Unless your use case can be handled by those parameters, you're stuck with filtering on the output side.除非您的用例可以由这些参数处理,否则您将不得不在输出端进行过滤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.