Quick way to list all files in Amazon S3 bucket?

前端 未结 28 1796
星月不相逢
星月不相逢 2020-11-28 01:32

I have an amazon s3 bucket that has tens of thousands of filenames in it. What\'s the easiest way to get a text file that lists all the filenames in the bucket?

28条回答
  •  遥遥无期
    2020-11-28 01:54

    In PHP you can get complete list of AWS-S3 objects inside specific bucket using following call

    $S3 = \Aws\S3\S3Client::factory(array('region' => $region,));
    $iterator = $S3->getIterator('ListObjects', array('Bucket' => $bucket));
    foreach ($iterator as $obj) {
        echo $obj['Key'];
    }
    

    You can redirect output of the above code in to a file to get list of keys.

提交回复
热议问题