Is there a way to download a file from Google Cloud Storage in PHP ? Instead of just reading it

Viewed 1749

Is there a way to download a file from Google Cloud Storage in PHP,instead of just reading it and save the content to a file using php functions ?

My code is 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 that Google Cloud Storage supports uploading . I use $storage->objects->insert(...) which works fine,but I can't find a similar function to use for download.

Thank you!

1 Answers
Related