[英]Is there a way to download a file from Google Cloud Storage in PHP ? Instead of just reading it
有没有办法从PHP 下载谷歌云端存储文件, 而不是只是阅读它并使用PHP功能将内容保存到文件 ?
我的代码是这样的:
$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云端存储支持上传 。 我使用$ storage-> objects-> insert(...) ,它工作正常,但我找不到类似的功能用于下载。
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.