问题
I have a Google Cloud Storage bucket "MyBucket" and it have 20 items. I would like to get those file name in my appengine PHP application.
I'm Looking whether we can get the list using App Engine's built-in Google Cloud Storage (GCS) stream wrapper.
Something Like this:
require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;
$bucket_name = 'gs://my-bucket/';
$file_list = CloudStorageTools::list($bucket_name); //Won't Work. Function like this
回答1:
based on ref. documentation for CloudStorateTools there is no such thing like listing files. Consider to use different API for accessing Google Cloud Storage like JSON API. For list function you can check this link.
回答2:
I've found an answer. I hope this is correct . It is strange we cannot find this on documentation for php.
$storage = new Google_Service_Storage($client);
$listObjects = $storage->objects->listObjects($bucket, array());
$items = $listObjects->getItems();
foreach ($items as $item) {
print_r($item["name"]);
}
来源:https://stackoverflow.com/questions/24657549/get-list-of-files-in-google-cloud-storage-appengine-php