Get list of Files in Google Cloud Storage (Appengine PHP)

≡放荡痞女 提交于 2021-02-04 19:42:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!