php - $s3->getObject 返回私有类(不能访问属性)
问题描述
我正在尝试编写一个从我的 S3 存储桶下载内容的函数。我遇到的主要问题是,$s3->getObject
返回具有私有属性的类。
我"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
我该怎么做才能让我的课程公开并且可以访问这些属性?如果您需要任何其他信息,请告诉我,我会提供。谢谢
解决方案
我想通了。您必须像访问数组一样访问此对象属性。
就我而言,如果我尝试访问 $response 的内容类型,我需要调用
$response['ContentType']
推荐阅读
- regex - Perl:里面有变量的正则表达式?
- python - [帮助]从csv文件中提取并输出txt(python)[帮助]
- c# - C# 中 WPF 的 WinML 和 OnnxRuntime 之间的区别
- java - 为什么我不能将对象数组转换为泛型类的泛型子类数组?
- memory - 80386 微处理器分段单元大小
- c# - 获取 OrderedDictionary 的值
- sql - 使用多个 OR 条件优化查询
- python - 定义的前缀不会从 json 文件不和谐中加载
- forms - 是否有任何解决方法来指定发件人的电子邮件地址,以便在提交表单时自动发送电子邮件?
- python - 如果带有布尔函数调用的条件在 Python 中始终为 True