dongyi8383 2017-01-30 12:07
浏览 326

使用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:

  • 写回答



      相关推荐 更多相似问题


      • ¥15 session失效问题
      • ¥15 GMS地下水数值模拟无法打开
      • ¥15 树型结构的数据怎么匹配分支
      • ¥15 stm32F4用.引不出来结构体成员怎么解决
      • ¥15 .exe文件打不开怎么解决?
      • ¥30 Syntax Error: TypeError: this.getOptions is not a function的问题
      • ¥15 eclipse Android环境搭建
      • ¥15 unity中脚本之间的继承有什么作用
      • ¥15 C语言内存对齐代码不太理解
      • ¥15 uniapp中的uni-file-picker组件多图上传,删除,显示。以及C#.Net后端处理问题