$s3->getObject returns private class (无法访问属性)
$s3->getObject returns private class (can't access properties)
我正在尝试编写一个从我的 S3 存储桶下载内容的函数。我遇到的主要问题是,$s3->getObject
returns class 具有私有属性。
我正在通过 composer 使用 "aws/aws-sdk-php": "^3.54"
,这是我的方法。
我的主控器
public function download($idDocument = null) {
$document = $this->Documents->get(['where' => ['id_document' => $idDocument]]);
$document = $document[0];
// Download file from S3
$this->load->library('s3');
$response = $this->s3->downloadFromS3($document->path);
var_dump($response);
die();
}
这是我在上层控制器中调用的 S3 库
public function authorize() {
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'eu-central-1',
'credentials' => [
'key' => $this->config->config['s3_access_key'],
'secret' => $this->config->config['s3_secret_key']
]
]);
return $s3;
}
public function downloadFromS3($uniqueIdTypeAndName) {
$s3 = $this->authorize();
$object = $s3->getObject([
'Bucket' => $this->config->config['s3_bucket_name'],
'Key' => $uniqueIdTypeAndName
]);
return $object;
}
这是我 var_dump($response);
我的库函数
的响应
所以当我尝试调用 $response->ContentType 时,我得到 Message: Undefined property: Aws\Result::$ContentType
我该怎么做才能使我的 class 变为 public 并且可以访问这些属性?如果您需要任何其他信息,请告诉我,我会提供。谢谢
我明白了。您必须像访问数组一样访问此对象属性。
在我的例子中,如果我尝试访问 $response 的内容类型,我需要调用
$response['ContentType']
我正在尝试编写一个从我的 S3 存储桶下载内容的函数。我遇到的主要问题是,$s3->getObject
returns class 具有私有属性。
我正在通过 composer 使用 "aws/aws-sdk-php": "^3.54"
,这是我的方法。
我的主控器
public function download($idDocument = null) {
$document = $this->Documents->get(['where' => ['id_document' => $idDocument]]);
$document = $document[0];
// Download file from S3
$this->load->library('s3');
$response = $this->s3->downloadFromS3($document->path);
var_dump($response);
die();
}
这是我在上层控制器中调用的 S3 库
public function authorize() {
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'eu-central-1',
'credentials' => [
'key' => $this->config->config['s3_access_key'],
'secret' => $this->config->config['s3_secret_key']
]
]);
return $s3;
}
public function downloadFromS3($uniqueIdTypeAndName) {
$s3 = $this->authorize();
$object = $s3->getObject([
'Bucket' => $this->config->config['s3_bucket_name'],
'Key' => $uniqueIdTypeAndName
]);
return $object;
}
这是我 var_dump($response);
我的库函数
所以当我尝试调用 $response->ContentType 时,我得到 Message: Undefined property: Aws\Result::$ContentType
我该怎么做才能使我的 class 变为 public 并且可以访问这些属性?如果您需要任何其他信息,请告诉我,我会提供。谢谢
我明白了。您必须像访问数组一样访问此对象属性。
在我的例子中,如果我尝试访问 $response 的内容类型,我需要调用
$response['ContentType']