Я установил SDK Amazon для PHP, используя композитор. Я скопировал пример код и реализован в мою систему, но при попытке загрузить файл, я получаю следующее (я сделал пути общую для безопасности):Amazon S3 Ошибка загрузки PermanentRedirectException
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 Я указываю SDK 3.1 Amazon.
В моем 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();
}
}
Для жизни меня я не могу понять, что я делаю неправильно. Кажется, я не могу найти ссылку на эту ошибку, когда Googling.
Любая помощь будет оценена положительно. Документация Amazon ужасно бесполезна.
Заранее спасибо.
Вы уверены, что ведро находится у нас на востоке (Вирджиния)? –
'Bucket' => $ awsCredentials ['bucket'], Это значение Bucket пустое? а не путь/место. Нет? –