2016-08-04 230 views
2

請幫我一把!我正在使用aws-php-sdk在aws s3服務器上上傳文件。我可以將文件夾從我們的服務器移動到aws s3服務器,並且可以刪除文件,但無法創建目錄/ 我總是收到拒絕訪問錯誤。PHP如何在aws s3存儲桶中創建文件夾?

的錯誤是

Error executing "PutObject" on "https://s3.amazonaws.com/***/***/***/picture/"; AWS HTTP error: Client error: `PUT https://s3.amazonaws.com/***/****/****/picture/` resulted in a `403 Forbidden` response: <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>CE24E8 (truncated...) AccessDenied (client): Access Denied - <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>CE24E8FFC9216978</RequestId><HostId>DHdN6tcopPTP9IsVu/qGWClf1+hAoWv7CNUWJRsOPWia4SfQYQ+VPYgJ3+vlqqRBNbYWB34gEQ0=</HostId></Error> 


and here is my code 

    $s3Client = new Aws\S3\S3Client([ 
      'version' => AWS_VERSION, 
      'region' => AWS_REGION, 
      'credentials' => [ 
       'key' => AWS_KEY, 
       'secret' =>AWS_SECRET, 
      ], 
     ]); 


//code to create the directory 

     $s3Client->putObject(array(
      'Bucket' => AWS_BUCKET, // Defines name of Bucket 
      'Key' => "picture/", //Defines Folder name 
      'Body' => "", 
      'ACL' => 'public-read' // Defines Permission to that folder 
     )); 

//I have also used along with full AWS_PATH, that is my uploading direcctory path on the aws server but none of them is working always gets the same error. 

     $s3Client->putObject(array(
      'Bucket' => AWS_BUCKET, // Defines name of Bucket 
      'Key' => AWS_PATH . "picture/", //Defines Folder name 
      'Body' => "", 
      'ACL' => 'public-read' // Defines Permission to that folder 
     )); 

回答

1

我想出的解決方案我自己。 實際上在創建一個新目錄時,我不能授予新目錄的權限,因爲我不是桶的所有者。我使用桶作爲第三方。所以從代碼我必須刪除'ACL'=>'公衆閱讀',現在我的代碼是

$s3Client->putObject(array(
      'Bucket' => AWS_BUCKET, // Defines name of Bucket 
      'Key' => AWS_PATH . "picture/", //Defines Folder name 
      'Body' => "", 
     )); 
相關問題