gpt4 book ai didi

php - 将 aws/aws-sdk-php 与谷歌云存储一起使用

转载 作者:可可西里 更新时间:2023-11-01 00:20:40 32 4
gpt4 key购买 nike

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');

但这给了我一个错误:

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');

最佳答案

关于php - 将 aws/aws-sdk-php 与谷歌云存储一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25595041/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com