Amazon S3 上传错误 PermanentRedirectException

2024-04-16

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

致命错误:未捕获异常“Aws\S3\Exception\PermanentRedirectException”,消息为“请求时遇到永久重定向”https://s3.amazonaws.com/mybucket/path/to/image.jpg https://s3.amazonaws.com/mybucket/path/to/image.jpg。您确定该存储桶使用了正确的区域吗?在 /path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php:49 堆栈跟踪:#0 /path/to/vendor/guzzlehttp/promises/src/Promise.php(199): Aws\S3\PermanentRedirectMiddleware->Aws\S3{closure}(对象(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 在 /path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php 第 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();
    }
}

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

任何帮助将不胜感激。亚马逊的文档非常无用。

提前致谢。


啊。我可以发誓我正在使用 us-east-1 区域。显然不是。这个错误确实是由于区域错误造成的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Amazon S3 上传错误 PermanentRedirectException 的相关文章

随机推荐