【发布时间】:2016-03-17 08:34:32
【问题描述】:
有没有办法用 PHP 从 Google Cloud Storage 中下载文件,而不是仅仅读取文件并使用 php 函数将内容保存到文件中?? p>
我的代码是这样的:
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);
$storage = new Google_Service_Storage($this->gcsClient);
$object = $storage->objects->get($this->bucket, $file);
$request = new Google_Http_Request($object['mediaLink'], 'GET');
$signed_request = $this->gcsClient->getAuth()->sign($request);
$http_request = $this->gcsClient->getIo()->makeRequest($signed_request);
$options = ['gs' => ['Content-Type' => 'text/plain']];
echo $http_request->getResponseBody();
$ctx = stream_context_create($options);
file_put_contents($destination, $http_request->getResponseBody(),0,$ctx);
我发现 Google Cloud Storage 支持上传。我使用 $storage->objects->insert(...) 工作正常,但我找不到类似的函数用于下载。
谢谢!
【问题讨论】:
标签: php download google-cloud-storage