有没有办法在PHP中从Google Cloud Storage下载文件,而不仅仅是读取它并使用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);
我发现谷歌云存储支持上传。我使用 $storage->objects->insert(...) 工作正常,但我找不到类似的函数用于下载。
谢谢!
<?php
CloudStorageTools::serve('gs://mybucket/myfile.txt',
['save_as' => 'myfile.txt',
'content_type' => 'text/plain']););
另请参阅文档和 Stuart Langley 对此问题的回答。