谷歌云存储(与谷歌硬盘不同)似乎与s3api兼容:
https://developers.google.com/storage/docs/migrating#migration-simple
有人知道我是否可以使用AWS/AWS SDK PHP(https://packagist.org/packages/aws/aws-sdk-php)包并将其配置为连接到我的谷歌云存储而不是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');
但这给了我一个错误:
致命错误:uncaught aws\s3\exception\invalidaccesskeyidexception:aws错误代码:invalidaccesskeyid,状态代码:403,aws请求ID:bf7c1317719a4c67,aws错误类型:client,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包来连接到谷歌云存储呢?
编辑
下面是使它工作的代码:
<?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');
最佳答案
endpoint
是错误的键。应该是base_url
。
http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#setting-a-custom-endpoint