And*_*sen 4 php amazon-s3 amazon-web-services
我已经使用composer安装了适用于PHP的Amazon SDK.我复制了示例代码并将其实现到我的系统中,但是当我尝试上传文件时,我得到以下内容(我已经将路径设为通用的安全性):
致命错误:未捕获的异常'Aws\S3\Exception\PermanentRedirectException',消息'在请求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在第49行的/path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php
在我的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();
}
}
Run Code Online (Sandbox Code Playgroud)
对于我的生活,我无法弄清楚我做错了什么.在谷歌搜索时,我似乎无法找到任何对此错误的引用.
任何帮助将非常感谢.亚马逊的文档非常无益.
提前致谢.