【问题标题】:Is there anyway to connect to Google Cloud Storage from Google Compute Engine?无论如何从谷歌计算引擎连接到谷歌云存储?
【发布时间】:2016-06-17 16:48:01
【问题描述】:

目前我正在为我的 php 项目使用谷歌应用引擎。我决定将我的项目迁移到 Google Compute Engine,但我无法通过 php 连接到 Google Cloud Storage。有没有办法解决这个问题?

更新:

我发现这是可以实现的,我需要一些使用服务器 API 来获取存储内容的示例。这就是我所做的。

require_once 'GoogleAPI/autoload.php';
$projectId = "dummyid";
$client = new Google_Client();
$client->setApplicationName("Gave");
$client->setDeveloperKey("SERVERKEY");
$client->addScope(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);

$storage = new Google_Service_Storage($client);
$buckets = $storage->buckets->listBuckets($projectId);
foreach ($buckets['items'] as $bucket) {
   printf("%s\n", $bucket->getName());
}

但它仍然不起作用。服务器密钥是否仅限于访问某些控制?它给了我一个错误 500。

【问题讨论】:

    标签: php google-app-engine google-cloud-storage google-compute-engine google-app-engine-php


    【解决方案1】:

    您当然可以使用来自 Google Compute Engine (GCE) 的 Google Cloud Storage (GCS)。您会发现这是访问 GCS 的最快方式之一。但是,当您不使用 App Engine 时,您无法使用相同的 App Engine PHP 库访问 GCS。

    用于在 AppEngine 以外的环境中使用 PHP 的规范客户端库是 Google APIs Client Library for PHP。您可以在此处找到有关使用该库访问 GCS 的演示和教程:https://cloud.google.com/storage/docs/json_api/v1/json-api-php-samples

    作为第二个选项,新的gcloud-php 项目具有对 GCS 的基本支持。

    最后,作为第三种选择,用于通过 HTTP 请求直接访问 GCS 的公共 API 有很好的文档记录,并且在 GCE 中运行良好。

    【讨论】:

    • 是的,目前我正在查看这个示例。感谢您让我知道 GCS 也适用于 GCE。但目前我对某些事情感到很困惑。它需要我键入 define('DEFAULT_OBJECT', 'DEFAULT_OBJECT');什么是对象价值?我尝试了很多值,但似乎不起作用。
    • 我没有看到 DEFAULT_OBJECT 位,你能把我链接到它吗?
    • 对象的link。我正在尝试使用服务器 api 密钥来运行,但它似乎不起作用。这是它的屏幕截图。 screenshot.服务器密钥有限制吗?
    猜你喜欢
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多