我已经使用 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/