3

Google Cloud Storage(与 Google Drive 不同)似乎与 S3 API 兼容:

https://developers.google.com/storage/docs/migrating#migration-simple

有谁知道我是否可以使用 aws/aws-sdk-php ( https://packagist.org/packages/aws/aws-sdk-php ) 包并将其配置为连接到我的 Google Cloud Storage 而不是 AWS S3?

我尝试了以下代码:

<?php 
use Aws\S3\S3Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\AwsS3 as Adapter;
require_once 'vendor/autoload.php';
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);


$client = S3Client::factory(array(
    'key'    => 'MY_GCS_KEY',
    'secret' => 'MY_GCS_SECRET',
    'endpoint' => 'storage.googleapis.com'
));
$filesystem = new Filesystem(new Adapter($client, 'MY_GCS_BUCKET'));
$filesystem->write('filename.txt', 'contents');

但这给了我一个错误:

致命错误:未捕获的 Aws\S3\Exception\InvalidAccessKeyIdException:AWS 错误代码:InvalidAccessKeyId,状态代码:403,AWS 请求 ID:BF7C1317719A4C67,AWS 错误类型:客户端,AWS 错误消息:您提供的 AWS 访问密钥 ID 不存在我们的记录。,用户代理:aws-sdk-php2/2.6.15 Guzzle/3.9.2 curl/7.32.0 PHP/5.5.4-1+debphp.org~raring+1 在/var/www/prudhub中抛出/dev/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php 在第 91 行

任何人都知道如何或是否可以正确设置 aws/aws-sdk-php 包以连接到 Google Cloud Storage?

编辑

这是使它工作的代码:

<?php 
use Aws\S3\S3Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\AwsS3 as Adapter;
require_once 'vendor/autoload.php';


$client = S3Client::factory(array(
    'key'    => 'MY_GCS_KEY',
    'secret' => 'MY_GCS_SECRET',
    'base_url' => 'https://storage.googleapis.com'
));
$filesystem = new Filesystem(new Adapter($client, 'MY_GCS_BUCKET'));
$filesystem->write('filename.txt', 'contents');
4

1 回答 1

7

endpoint是错误的钥匙。应该是base_url

http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#setting-a-custom-endpoint

于 2014-08-31T20:19:04.730 回答