AWS PHP SDK-致命错误问题

AWS PHP SDK-致命错误问题,php,amazon-web-services,amazon-s3,aws-sdk,Php,Amazon Web Services,Amazon S3,Aws Sdk,我试图连接到我的S3,通过我的服务器上传一个文件,但是每当我尝试运行PHP时,我都会遇到下面的错误。我包括了版本和地区,但问题仍然存在 错误: Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Missing required client configuration options: region: (string) A "region" configuration value is require

我试图连接到我的S3,通过我的服务器上传一个文件,但是每当我尝试运行PHP时,我都会遇到下面的错误。我包括了版本地区,但问题仍然存在

错误:

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对象。您放的钥匙放错地方了,请按以下步骤操作

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

希望有帮助

您必须创建一个S3对象。您放的钥匙放错地方了,请按以下步骤操作

$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")
);

对于
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")
);

我把信息放错地方了,它需要在key/secret下。已解决。是的,这就是我指出的:)我的信息放在错误的部分,它需要在key/secret下。是的,这就是我指出的:)你们有php libxml包吗?如果未安装,请安装并重新启动apacheI意识到我的密钥错误!它现在使用上述方法上载,但在文件中我只接收路径。如果我将键指定为
sample.html
,但为文件路径添加
/srv/http/test/setup.html
。在s3上的sample.html内部,我只能看到
/srv/http/test/setup.html
它没有上载文件,我也输入了位置,因为您声明
Body
而不是
SourceFile
$keyname应该是您的对象键您的帖子缺少的是SourceFile,它与声明为非正文的源文件一起工作。您有php libxml包吗?如果未安装,请安装并重新启动apacheI意识到我的密钥错误!它现在使用上述方法上载,但在文件中我只接收路径。如果我将键指定为
sample.html
,但为文件路径添加
/srv/http/test/setup.html
。在s3上的sample.html内部,我只能看到
/srv/http/test/setup.html
它没有上载文件,我也输入了位置,因为您声明
Body
not
SourceFile
$keyname应该是您的对象键。您的帖子缺少的是SourceFile,它与声明为not Body的SourceFile一起工作。