PHP 的 AWS SDK - 致命错误问题

AWS SDK for PHP - Fatal Error Issue

我正在尝试连接到我的 S3 以通过我的服务器上传文件,但每当我尝试 运行 PHP 时,我都会遇到以下错误。我包括了 VersionRegion 但问题仍然存在?

错误:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Missing required client configuration options: region: (string) A "region" configuration value is required for the "s3" service (e.g., "us-west-2"). A list of available public regions and endpoints can be found at http://docs.aws.amazon.com/general/latest/gr/rande.html. version: (string) A "version" configuration value is required. Specifying a version constraint ensures that your code will not be affected by a breaking change made to the service. For example, when using Amazon S3, you can lock your API version to "2006-03-01". Your build of the SDK has the following version(s) of "s3": * "2006-03-01" You may provide "latest" to the "version" configuration value to utilize the most recent available API version that your client's API provider can find. Note: Using 'latest' in a production application is not recommended. A list of available API versions can be found on each client's API documentation page: http:/ in /srv/http/auploader/include/Aws/ClientResolver.php on line 364 

我的代码:

<?PHP
require '/srv/http/test/include/aws-autoloader.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

$bucket = 'testbucket';
$keyname = 'sample';
// $filepath should be absolute path to a file on disk                      
$filepath = '/srv/http/testfile/setup.html';

// Instantiate the client.
$s3 = S3Client::factory(array(
    'key'    => 'blank',
    'secret' => 'blank'
));

try {
    // Upload data.
    $result = $s3->putObject(array(
        'Bucket' => $bucket,
        'Key'    => $keyname,
        'SourceFile'   => $filepath,
        'ACL'    => 'public-read',
        'Region'  => 'eu-west-1',
        'Version' => '2006-03-01'
    ));



    // Print the URL to the object.
    echo $result['ObjectURL'] . "\n";
} catch (S3Exception $e) {
    echo $e->getMessage() . "\n";
}
?>

您必须创建 S3 的对象。而且你放的key放错了请按如下操作

$s3 = S3Client::factory([
                'version'     => 'latest',
                'region'      => 'eu-west-1',
                'credentials' => [
                    'key'    => "your s3 bucket key",
                    'secret' => "your s3 bucket secret key",
                ]
            ]);

通过使用 s3 对象,您可以实现 putObject 类似这样的方法。

$result = $s3->putObject(array(
            'Bucket'     => "yourbucket name",
            'Key'        => $keyName,
            'SourceFile' => $filepath,
            'ACL'        => 'public-read', //for making the public url
            'Version'    => '2006-03-01'
));
        ));

希望对您有所帮助!

SES AWS SDK v3 使用

/*
* 1. version as `2010-12-01`
* 2. version as Eg. `us-east-1`.
*/
ini_set("display_errors", 1);
Aws\Ses\SesClient::factory(array(
        'credentials' => array(
            'key' => "someKey",
            'secret' => "someSecret",
        ),
        "region" => "us-east-1",
        "version" => "2010-12-01")
);