【发布时间】:2021-07-03 19:03:35
【问题描述】:
我正在使用 aws-sdk-php 库在 Linode 上的 S3 服务器上工作,由于某种原因,我无法确定我无法创建存储桶。已经创建了 2 个存储桶,我知道连接正常,因为我可以随意操作和处理这些存储桶。 但是,当我尝试创建新存储桶时,收到 400 错误消息。我的代码:
define('AWS_KEY', 'my-key');
define('AWS_SECRET_KEY', 'my-secret-key');
$ENDPOINT = 'http://eu-central-1.linodeobjects.com';
$client = new S3Client([
'region' => 'eu-central-1',
'version' => '2006-03-01',
'endpoint' => $ENDPOINT,
'credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
],
'use_path_style_endpoint' => true
]);
try {
$result = $client->createBucket(['Bucket' => 'test']);
} catch (S3Exception $e) {
echo $e->getMessage();
}
我尝试了以下调用 createBucket 方法的选项:
$result = $client->createBucket([
'ACL' => 'private',
'Bucket' => 'test',
'CreateBucketConfiguration' => [
'LocationConstraint' => 'eu-central-1'
]
]);
$result = $client->createBucket([
'Bucket' => 'test',
'LocationConstraint' => 'eu-central-1'
]);
无论我运行哪一个,我都会收到以下错误消息:
在“http://eu-central-1.linodeobjects.com/test”上执行“CreateBucket”时出错; AWS HTTP 错误:客户端错误:PUT http://eu-central-1.linodeobjects.com/test 导致400 Bad Request 响应:InvalidLocationConstraintThe specified location-const (truncated...) InvalidLocationConstraint (client): The specified location-constraint is not valid - InvalidLocationConstraintThe specified location-constraint is not有效testtx00000000000000a3d5d24-00606e2f87-1549e3f-default1549e3f-default-default
我对 PHP 中的这类事情很陌生,这就是为什么我试图“按书本”做所有事情(尽可能地遵循文档),所以我真的不明白发生了什么。
编辑:我发现了更多与此相关的问题。使用 CyberDuck,我可以管理 S3,通过它我创建了一些存储桶(比如“测试”)。使用 aws-sdk-php 我可以使用 listBuckets 正确列出它们,甚至可以将对象放入其中,但是 getBucketCors() 等一些函数会给出错误消息:
在“http://eu-central-1.linodeobjects.com/test?cors”上执行“GetBucketCors”时出错; AWS HTTP 错误:客户端错误:GET http://eu-central-1.linodeobjects.com/test?cors 导致 404 Not Found 响应:NoSuchCORSConfigurationtestNoSuchCORSConfigurationtesttx00000000000000a965dee-00606f69c5-1549e27-default1549e27-default-default
【问题讨论】:
标签: php amazon-s3 aws-php-sdk