user3911183
user3911183

Reputation: 797

AWS how to list all files containing a string in a bucket ?

plz here is the code i use to fetch all the files in a bucket s3 :

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

$client = S3Client::factory(array(
        'key'       => 'key',
        'secret'    => 'secret',
        'region'    => 'eu-east-1'
    ));
$client->registerStreamWrapper();
$objects = $client->getListObjectsIterator(array(
    'Bucket' => "bucket_name",
    'Prefix' => 'folder_name/'
));

How to get only files which names are containing a string ?

Thanks.

Upvotes: 0

Views: 1564

Answers (1)

Daniel777
Daniel777

Reputation: 871

That's impossible to do via S3 API, because S3 API lets you filter by string ONLY if that string is a prefix for the keys you are listing.

Therefore, you have to list all the keys, get that result to a variable and programatically filter that list later.

Of course, you can get a shorter list to start by using the prefix filter when you retrieve the list in first place.

Upvotes: 3

Related Questions