将aws / aws-sdk-php与Google云端存储配合使用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了将aws / aws-sdk-php与Google云端存储配合使用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1880字,纯文字阅读大概需要3分钟。
内容图文
Google云端存储(与Google云端硬盘不同)似乎与S3 API兼容:
https://developers.google.com/storage/docs/migrating#migration-simple
有谁知道我是否可以使用aws / aws-sdk-php(https://packagist.org/packages/aws/aws-sdk-php)软件包并将其配置为连接到我的Google云端存储而不是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');
但这给了我一个错误:
Fatal error: Uncaught Aws\S3\Exception\InvalidAccessKeyIdException: AWS Error Code: InvalidAccessKeyId, Status Code: 403, AWS Request ID: BF7C1317719A4C67, AWS Error Type: client, AWS Error Message: The AWS Access Key Id you provided does not exist in our records., User-Agent: aws-sdk-php2/2.6.15 Guzzle/3.9.2 curl/7.32.0 PHP/5.5.4-1+debphp.org~raring+1 thrown in /var/www/prudhub/dev/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91
任何人都知道如何或者我是否可以正确设置aws / aws-sdk-php包以连接到Google云端存储?
编辑
以下是使其工作的代码:
<?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');
解决方法:
端点是错误的密钥.它应该是base_url.
http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#setting-a-custom-endpoint
内容总结
以上是互联网集市为您收集整理的将aws / aws-sdk-php与Google云端存储配合使用全部内容,希望文章能够帮你解决将aws / aws-sdk-php与Google云端存储配合使用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。