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

使用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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里