AWS S3获取包含文本的密钥 [英] AWS S3 get keys containing text

查看:97
本文介绍了AWS S3获取包含文本的密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从S3中获取文件.

I'm trying to fetch the files from S3.

和往常一样,我的文件在存储桶中的组织方式如下:

As usual, my files are organised in the bucket as below:

bucket/<prefixes>/files

我要检索具有特定文件名的文件

I want to retrieve files having specific file names

例如:

  1. 以给定文本(myfile- *)开头的文件
  2. 具有特定扩展名(* .csv)的文件
  3. 具有特定文本( text )的文件名

对于第一种情况,我可以使用如下前缀:

For the first scenario, I can get away using prefix as below:

ObjectListing objectListing = s3Client.listObjects(bucketName, "test/myfile");

但是对于其他两种情况,我找不到任何解决方案.

But for the other 2 cases, I'm not able to find any solution.

我尝试使用通配符,如下所示:

I tried using wildcards as below:

ObjectListing objectListing = s3Client.listObjects(bucketName, "test/*.csv");

但是它没有返回任何结果.

But it didn't return any result.

是否有任何解决方法(除了在我的代码中获取键列表和过滤之外)?

Is there any workaround for this (other than getting the list of keys and filtering within my code)??

感谢您的帮助.

推荐答案

您的用例非常普遍.

我不知道有任何S3 API允许您执行除前缀匹配之外的任何操作.

I am unaware of any S3 API that allows you to do anything other than prefix-matching.

处理此问题的方法是维护文件名(以及其他元数据)的单独的可搜索副本.换句话说,在每个文件的关系数据库的表中都有一行.或者,您可以维护一个列出所有文件名的索引"文件.

The way to deal with this is to maintain a separate, searchable copy of the file names (and perhaps other metadata). In other words, have a row in a table in a relational database for each file. Or you might maintain an "index" file that lists all of the file names.

如果通过代码执行文件创建/删除操作,则可以添加所需的代码以使文件列表与存储桶保持同步.如果不是,则可以使用

If the file creation/deletion is performed through your code, you can add the required code to keep the file list in sync with your bucket. If not, then you can use S3 event notifications to drive the file list updates.

要按文件名搜索时,可以在文件列表或数据库表中查找以获取匹配的文件名.然后按S3键以执行所需的任何操作.

When you want to search by file names, you look in the file list or database table to get the matching file names. Then hit S3 to do whatever operation is required.

这篇关于AWS S3获取包含文本的密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆