dongyi8383 2017-01-30 12:07
浏览 329
已采纳

使用AWS PHP SDK列出AWS S3 Bucket中文件夹(前缀)内的所有文件

I'm having some troubles listing all the files within certain prefix of an AWS S3 Bucket.

I have searched and search, but only seem to be able to find the same information:

try {
$objects = $s3Client->getIterator('ListObjects', array(
    'Bucket' => 'BUCKETNAME',
    'Prefix' => '/uploads/content/document/'
));
    foreach ($objects as $object) {
        echo $object['Key'] . "
";
    }
} catch (S3Exception $e) {
    echo $e->getMessage() . "
";
}

This will give back a fair bit of information if I print_r($objects) however, nothing is echo'd out in the loop, and no matter what I try, I can't seem to get it to list any files.

I actually have another 6 folders I want to retrieve a list of files from, however, obviously need to get it working with just document for now.

I have tried removing the final / on the prefix, as well as using 'listObjects':

$s3Client->getIterator('listObjects' ...

and even with trying a different method of just ListObjects or ListObjectsV2 (found this information). The first one works but again doesn't list any files, and the second method isn't found.

$s3Client->ListObjects(array( ...
$s3Client->ListObjectsV2(array( ...

No doubt i'm missing something. All I want to achieve is the list of all files names within each of the folders/prefixes, so I can list these and use some clever jQuery to add them into a document when selected in our CMS, sure there should be more information on this somewhere!!!

Any help would be much appreciated.

print_r($objects) returns: http://pastebin.com/YwWLLsSK

  • 写回答

1条回答 默认 最新

  • douchen3562 2017-01-30 18:49
    关注

    You are missing most important key to set which is

    like this // 'ap-southeast-1' for asian region

                'region'  => 'ap-southeast-1',
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题