php - 按关键字搜索 S3 文件夹中的图像
问题描述
使用英文关键字从 S3 搜索和获取图像列表的最佳和简单方法是什么。还是我必须使用 Rekognition 将所有图像元数据存储到数据库中?
我的开发是使用 PHP。
解决方案
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = '*** Your Bucket Name ***';
// Instantiate the client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
// Use the high-level iterators (returns ALL of your objects).
try {
$objects = $s3->getPaginator('ListObjects', [
'Bucket' => $bucket
]);
echo "Keys retrieved!" . PHP_EOL;
foreach ($objects as $object) {
echo $object['Key'] . PHP_EOL;
}
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
// Use the plain API (returns ONLY up to 1000 of your objects).
try {
$result = $s3->listObjects([
'Bucket' => $bucket
]);
echo "Keys retrieved!" . PHP_EOL;
foreach ($result['Contents'] as $object) {
echo $object['Key'] . PHP_EOL;
}
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
因此此代码将返回您存储桶中的所有对象,您可以添加仅当密钥包含扩展名“jpg”、“jpeg”和“png”的逻辑,然后只需打印对象的密钥/名称
推荐阅读
- git - 有没有办法批量删除 git 分支?
- .net-core - DevExtreme Grid DateTime 列头过滤器格式
- python - A for loop works in Python but doest work in Django
- python - 如何使用 Selenium 和 Python 更新 AngularJs 输入标记值?
- entity-framework-core - EF Core:加载导航属性时更新 FK
- c# - 处理不明确的时间与夏令时
- python - 将元组作为参数传递时,函数中的位置参数似乎“重叠”
- java - 如何将 JsonNode 实例转换为实际的 pojo
- c# - 将文本块可见性与网格的自定义属性绑定
- java - 如何处理 JAXB 属性中的冒号(:)?