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

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

  • 写回答

1条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 如何抓这个函数的包wx.updateShareMenu
      • ¥15 需要数据分析!时间紧!
      • ¥15 关于免费论文查重系统的问题。
      • ¥15 朋友们,这个sim函数是出了什么问题了呢
      • ¥15 【MRT数据导入问题】MRT处理modis数据提示opening input header file怎么解决?
      • ¥15 嵌入式系统综合设计题有会的教一下嘛?
      • ¥15 yolov5转onnx验证出错
      • ¥15 proteus仿真LCD不点亮
      • ¥15 C语言红绿灯时间问题
      • ¥15 matlab仿真实现定位算法