From b303491e0f0dce79bbb9504b61cd61dfe61fdbf1 Mon Sep 17 00:00:00 2001 From: Junkins Date: Thu, 20 Jun 2019 18:51:52 +0900 Subject: [PATCH] =?UTF-8?q?S3=E3=81=AB=E9=96=A2=E3=81=99=E3=82=8B=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Behavior/BindableBehavior.php | 15 ++++++++------- Test/Case/Model/Behavior/BindableBehaviorTest.php | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Model/Behavior/BindableBehavior.php b/Model/Behavior/BindableBehavior.php index edfe850..269d43c 100644 --- a/Model/Behavior/BindableBehavior.php +++ b/Model/Behavior/BindableBehavior.php @@ -321,7 +321,7 @@ public function afterSave(Model $model, $created, $options = array()){ 'region' => Configure::read('Filebinder.S3.region'), 'version' => 'latest' ); - + $bucket = !empty($bindFields[$fieldName]['bucket']) ? $bindFields[$fieldName]['bucket'] : Configure::read('Filebinder.S3.bucket'); if (empty($bucket)) { //__('Validation Error: S3 Parameter Error'); @@ -1013,8 +1013,13 @@ protected function bindFile(Model $model, $data = array()) { //__('Validation Error: S3 Parameter Error'); return false; } - $options = array('key' => Configure::read('Filebinder.S3.key'), - 'secret' => Configure::read('Filebinder.S3.secret'), + $options = array( + 'credentials' => array( + 'key' => Configure::read('Filebinder.S3.key'), + 'secret' => Configure::read('Filebinder.S3.secret'), + ), + 'region' => Configure::read('Filebinder.S3.region'), + 'version' => 'latest' ); $bucket = !empty($bindFields[$fieldName]['bucket']) ? $bindFields[$fieldName]['bucket'] : Configure::read('Filebinder.S3.bucket'); if (empty($bucket)) { @@ -1022,10 +1027,6 @@ protected function bindFile(Model $model, $data = array()) { return false; } $s3 = S3Client::factory($options); - $region = !empty($bindFields[$fieldName]['region']) ? $bindFields[$fieldName]['region'] : Configure::read('Filebinder.S3.region'); - if (!empty($region)) { - $s3->setRegion($region); - } $urlPrefix = !empty($bindFields[$fieldName]['urlPrefix']) ? $bindFields[$fieldName]['urlPrefix'] : Configure::read('Filebinder.S3.urlPrefix'); $tmpFilePath = '/tmp/' . sha1(uniqid('', true)); diff --git a/Test/Case/Model/Behavior/BindableBehaviorTest.php b/Test/Case/Model/Behavior/BindableBehaviorTest.php index 7aee511..c84592b 100644 --- a/Test/Case/Model/Behavior/BindableBehaviorTest.php +++ b/Test/Case/Model/Behavior/BindableBehaviorTest.php @@ -418,7 +418,7 @@ public function testSaveS3(){ 'tmpPath' => CACHE, 'filePath' => $filePath, 'bucket' => AWS_S3_BUCKET, - 'acl' => Aws\S3\Enum\CannedAcl::PUBLIC_READ, + 'acl' => 'public-read', ), ); @@ -482,7 +482,7 @@ public function testRestoreS3(){ 'tmpPath' => CACHE, 'filePath' => $filePath, 'bucket' => AWS_S3_BUCKET, - 'acl' => Aws\S3\Enum\CannedAcl::PRIVATE_ACCESS, + 'acl' => 'private', ), ); @@ -552,7 +552,7 @@ public function testRestoreFalseS3(){ 'tmpPath' => CACHE, 'filePath' => $filePath, 'bucket' => AWS_S3_BUCKET, - 'acl' => Aws\S3\Enum\CannedAcl::PRIVATE_ACCESS, + 'acl' => 'private', ), );