【发布时间】:2018-10-26 04:58:47
【问题描述】:
我正在尝试编写一个从我的 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
我该怎么做才能让我的课程公开并且属性可以访问?如果您需要任何其他信息,请告诉我,我会提供。谢谢
【问题讨论】:
-
由于回复来自 Guzzle,我假设您可以使用
$response->getBody()->getContents();或(string) $response->getBody(); -
不抱歉这没有帮助...调用未定义的方法 Aws\Result::getBody()
-
天啊!!!我想通了...:/您必须将其称为数组 $response['ContentType']
-
好吧,给你。可能也想将其发布为答案。其他人也可能会遇到这个问题。
标签: php codeigniter amazon-s3 aws-sdk aws-php-sdk