我是 AWS s3 的新手,试图弄清楚如何在 php 中使用它。
我开始使用并且我可以使用 s3->listBuckets 方法列出我的所有存储桶,但是当我尝试列出此存储桶中的所有对象时,它失败了
PHP Fatal error: Uncaught Aws\S3\Exception\PermanentRedirectException: Encountered a permanent redirect while requesting https://s3.us-east-2.amazonaws.com/ischool.simplein?encoding-type=url. Are you sure you are using the correct region for this bucket? in /Users/momen/Desktop/studio/s3/sdk/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php:49 Stack trace:
关键是,我拥有的凭据是用于 us-west-2 帐户的,但是当我创建 s3 存储桶时,我选择将它托管在 eu-london。
复制问题的示例代码。
require('vendor/autoload.php');
// Use the us-west-2 region and latest version of each client.
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET
]
]);
$buckets = $s3->listBuckets(); // works
$bucket = $buckets['Buckets'][1]['Name'];
$objects = $s3->listObjects([ 'Bucket' => $bucket ]) // FAIL with permenant redirect
那么我应该使用哪个地区?为什么我可以列出存储桶,但不能使用它们?
最佳答案
所以第一个问题:
Which region should i use?
您应该使用区域
eu-west-2
Here是所有地区文档的链接。
现在来回答另一个问题:
How to utilize buckets?
这个错误看起来很明显,你有错误的区域。所以我会考虑改变地区,然后再试一次。
这是另一个相关问题:Amazon S3 Upload error PermanentRedirectException
关于php - aws s3 sdk php 在 getObjects 时遇到永久重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48801810/