【发布时间】:2014-12-01 16:10:19
【问题描述】:
好的,所以我尝试了几种方法将文件上传到我的 S3 帐户。终于发现自己到了某个地方并且 BOOM - 令人困惑的文档和似乎自相矛盾的奇怪错误消息。
好的,首先我没有使用作曲家或类似的东西,我正在用老式的方式做这件事:
require '/path/to/aws-autoload.php';
现在可以正确加载,并且我已将自动加载缩减为仅使用 Common 和 S3 类 - 不需要所有内容!
接下来我加载 S3 客户端和凭据:
use Aws\S3\S3Client;
use Aws\Common\Credentials\Credentials;
现在开始魔法发生的代码:
$file = '/path/to/' . $filename;
$credentials = new Credentials('KEY', 'SECRET KEY');
$s3 = S3Client::factory(array('credentials' => $credentials));
try{
$s3->putObject(array(
'Bucket' => 'sub.domain.com.s3.amazonaws.com',
'Body' => fopen($file, 'r'),
'ACL' => 'public-read',
));
} catch (S3Exception $e) {
$result = array(
'ok' => false,
'descr' => 'There was an error uploading the file to S3 : ' . $filename
);
}
我似乎遇到的问题是“桶”本身。
当我将存储桶格式化为 sub.domain.com 时,我从 AWS API 收到以下消息:
AWS 错误消息:您尝试访问的存储桶必须使用指定的终端节点进行寻址。请将所有未来请求发送到此端点:“sub.domain.com.s3.amazonaws.com”。
现在,当我像这样更改“存储桶”以匹配上述内容时:sub.domain.com.s3.amazonaws.com
我收到以下错误消息:
AWS 错误消息:指定的存储桶不存在
我做错了吗?有什么遗漏吗?不幸的是,AWS 文档还没有达到标准。 API 目前似乎自相矛盾。我知道所有的密钥都是正确的,所有的权限都是正确的。它从 301 - 重定向到 404 - 根据自己的建议未找到。
任何帮助/建议将不胜感激。我觉得我在这里有点绕圈子!
【问题讨论】:
-
不只是
sub.domain部分作为例子吗?我认为您应该首先将此值更改为您命名存储桶的任何名称。 -
我已经这样做了,我在此处发帖时将其设置为 sub.domain 以使其更通用,并且不会泄露我工作的网站。 KEY 和 SECRET KEY 也设置为正确的值
-
您是否尝试过使用
path-style URL(如http://s3.amazonaws.com/<bucket>)访问您的存储桶? -
是的,同样的结果:
<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><Bucket>sub.domain.com</Bucket><Endpoint>sub.domain.com.s3.amazonaws.com</Endpoint></Error> -
尝试使用 php s3 客户端检查您的存储桶名称是否对 S3 存储桶有效,
isValidBucketName($bucketName);,我认为问题可能是存储桶名称的格式.
标签: php amazon-web-services amazon-s3 aws-php-sdk