Amazon S3上传错误PermanentRedirectException [英] Amazon S3 Upload error PermanentRedirectException

查看:240
本文介绍了Amazon S3上传错误PermanentRedirectException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've installed the Amazon SDK for PHP using composer. I copied the example code and implemented into my system, but when I attempt to upload a file, I'm getting the following (i've made the paths generic for security):

致命错误:消息为在请求 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}(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):第49行的/path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php中的Gu

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.

In my composer.json I'm specifying the 3.1 Amazon SDK.

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

In my PHP I'm doing the following (based on several image files posted to the script):

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();
    }
}

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

For the life of me I can't figure out what I'm doing wrong. I can't seem to find any reference to this error when Googling.

任何帮助将不胜感激.亚马逊的文档极其无助.

Any help would be great appreciated. Amazon's documentation is horrendously unhelpful.

谢谢.

推荐答案

Argh.我本可以使用us-east-1地区的SWORN.显然不是.这个错误的确是由于错误的区域造成的.

Argh. I could have SWORN I was using the us-east-1 region. Apparently not. This error is indeed from having the wrong region.

这篇关于Amazon S3上传错误PermanentRedirectException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆