php - Amazon S3 上传错误 PermanentRedirectException

标签 php amazon-web-services amazon-s3

我已经使用 composer 安装了 Amazon SDK for PHP。我复制了示例代码并在我的系统中实现,但是当我尝试上传文件时,我得到以下信息(为了安全我已经将路径设为通用):

Fatal error: Uncaught exception 'Aws\S3\Exception\PermanentRedirectException' with message 'Encountered a permanent redirect while requesting https://s3.amazonaws.com/mybucket/path/to/image.jpg. Are you sure you are using the correct region for this bucket?' in /path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php:49 Stack trace: #0 /path/to/vendor/guzzlehttp/promises/src/Promise.php(199): Aws\S3\PermanentRedirectMiddleware->Aws\S3{closure}(Object(Aws\Result)) #1 /path/to/vendor/guzzlehttp/promises/src/Promise.php(152): GuzzleHttp\Promise\Promise::callHandler(1, Object(Aws\Result), Array) #2 /path/to/vendor/guzzlehttp/promises/src/TaskQueue.php(60): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}() #3 /path/to/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(96): GuzzleHttp\Promise\TaskQueue->run() #4 /path/to/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(123): Gu in /path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php on line 49

在我的 composer.json 中,我指定了 3.1 Amazon SDK。

在我的 PHP 中,我正在执行以下操作(基于发布到脚本的几个图像文件):

require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';

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

$credentials = new Credentials('my-accessKey', 'accessSecret');

try {
    $s3Client = S3Client::factory(array(
        'credentials' => $credentials,
        'region' => 'us-east-1',
        'version' => 'latest'
    ));
} catch (S3Exception $e) {
    print_r($e->getMessage());
}

foreach($file['files']['tmp_name'] as $key => $tmp_name ){
    $file_name = $file['files']['name'][$key];
    $file_tmp = $file['files']['tmp_name'][$key];

    try { 
        $result = $s3Client->putObject(array(
            'Bucket'    => $awsCredentials['bucket'],
            'Key'       => "horsePhotos/".$horseId."/".$file_name,
            'SourceFile' => $file_tmp,
            'ACL'       => 'public-read'
        ));
    } catch(PDOException $e) {
        echo $e->getMessage();
    }
}

对于我的生活,我无法弄清楚我做错了什么。在谷歌搜索时,我似乎找不到任何对此错误的引用。

如有任何帮助,我们将不胜感激。 Amazon 的文档非常无用。

提前致谢。

最佳答案

唉。我可以发誓我使用的是 us-east-1 区域。显然不是。这个错误确实是来自错误的区域。

关于php - Amazon S3 上传错误 PermanentRedirectException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34573437/

相关文章:

node.js - 在 AWS 上部署 React + Express

ios - AWS iOS API 中的 token 使用

python - AWS Lambda 无法从 S3 获取文件

php - 使用 phar 打包并部署 Yii2 Advance 应用程序

php - 使用 PHP 在证书库中读取证书

php - 将 PHP MySQL 查询输出转换为变量

azure - azure 的云存储服务?

node.js - 为什么我的 S3 存储桶中的视频没有缓冲到 html 视频标签?

java - AWS S3 访问被拒绝

php - 关于在 Javascript 和 PHP 之间共享验证规则的建议?