通过 PHP SDK 的 S3 客户端初始化错误
S3 client initialization error via PHP SDK
我正在尝试从 AWS PHP SDK 初始化 S3 客户端。我的代码如下:
$credentials = new Credentials(self::KEY, self::SECRET);
$s3_client = new S3Client([
'version' => 'latest',
'region' => $region,
'credentials' => $credentials
]);
但出现以下错误:
A PHP Error was encountered
Severity: 4096
Message: Argument 1 passed to Aws\Common\Client\AbstractClient::__construct() must implement interface Aws\Common\Credentials\CredentialsInterface, array given, called in /opt/showhouse/www/application/models/showhouse/common/services/aws/aws.php on line 47 and defined
Filename: Client/AbstractClient.php
Line Number: 73
我哪里出错了?我正在使用通过 Composer 安装的最新版本的 SDK。
我猜您正在使用 AWS PHP SDK 2.0 版。如果是这样,那么 S3Client 确实实现了 AbstractClient class。这意味着参数是:
__construct( Aws\Common\Aws\Common\Credentials\CredentialsInterface $credentials, Aws\Common\Aws\Common\Signature\SignatureInterface $signature, Guzzle\Common\Collection $config )
您尝试使用的 S3Client 实现来自 AWS PHP SDK 3.0 版。
建议:尝试使用下载的 zip 文件而不是 Composer 安装 AWS SDK
我在使用 Composer 安装 AWS SDK 时遇到了同样的问题,因为它似乎是来自以下 URL.
的 AWS 文档中推荐的方式
https://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html
但是,在阅读了 Grilly 的有用回答后,我决定尝试使用下载的 zip 文件来安装 AWS SDK。我这样安装后问题消失了
从 zip 文件中包含的 README 文件中,我可以找到一条通知,指出使用下载的 zip 文件安装的 AWS SDK 版本为 3.0。虽然我无法检查使用 Composer 安装的 AWS SDK 的版本,因为我找不到方法,但我猜测使用 Composer 安装的 AWS SDK 的版本有点旧,足以导致问题。
我遇到了同样的问题并通过使用 PHP 5.6 和 AWS SDK v3.x
解决了
我正在尝试从 AWS PHP SDK 初始化 S3 客户端。我的代码如下:
$credentials = new Credentials(self::KEY, self::SECRET);
$s3_client = new S3Client([
'version' => 'latest',
'region' => $region,
'credentials' => $credentials
]);
但出现以下错误:
A PHP Error was encountered
Severity: 4096
Message: Argument 1 passed to Aws\Common\Client\AbstractClient::__construct() must implement interface Aws\Common\Credentials\CredentialsInterface, array given, called in /opt/showhouse/www/application/models/showhouse/common/services/aws/aws.php on line 47 and defined Filename: Client/AbstractClient.php
Line Number: 73
我哪里出错了?我正在使用通过 Composer 安装的最新版本的 SDK。
我猜您正在使用 AWS PHP SDK 2.0 版。如果是这样,那么 S3Client 确实实现了 AbstractClient class。这意味着参数是: __construct( Aws\Common\Aws\Common\Credentials\CredentialsInterface $credentials, Aws\Common\Aws\Common\Signature\SignatureInterface $signature, Guzzle\Common\Collection $config )
您尝试使用的 S3Client 实现来自 AWS PHP SDK 3.0 版。
建议:尝试使用下载的 zip 文件而不是 Composer 安装 AWS SDK
我在使用 Composer 安装 AWS SDK 时遇到了同样的问题,因为它似乎是来自以下 URL.
的 AWS 文档中推荐的方式https://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html
但是,在阅读了 Grilly 的有用回答后,我决定尝试使用下载的 zip 文件来安装 AWS SDK。我这样安装后问题消失了
从 zip 文件中包含的 README 文件中,我可以找到一条通知,指出使用下载的 zip 文件安装的 AWS SDK 版本为 3.0。虽然我无法检查使用 Composer 安装的 AWS SDK 的版本,因为我找不到方法,但我猜测使用 Composer 安装的 AWS SDK 的版本有点旧,足以导致问题。
我遇到了同样的问题并通过使用 PHP 5.6 和 AWS SDK v3.x
解决了