Is there a way to download a file from Google Cloud Storage in PHP ? Instead of just reading it -
is there way download file google cloud storage in php,instead of reading , save content file using php functions ?
my code this:
$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);
i've found google cloud storage supports uploading . use $storage->objects->insert(...) works fine,but can't find similar function use download.
thank you!
<?php cloudstoragetools::serve('gs://mybucket/myfile.txt', ['save_as' => 'myfile.txt', 'content_type' => 'text/plain']););
see documentation , stuart langley's answer question.
Comments
Post a Comment