Google\Cloud\Storage\StorageObject::downloadAsString PHP Method

downloadAsString() public method

Example: $string = $object->downloadAsString(); echo $string;
public downloadAsString ( array $options = [] ) : string
$options array [optional] { Configuration Options. @type string $encryptionKey An AES-256 customer-supplied encryption key. It will be neccesary to provide this when a key was used during the object's creation. If provided one must also include an `encryptionKeySHA256`. @type string $encryptionKeySHA256 The SHA256 hash of the customer-supplied encryption key. It will be neccesary to provide this when a key was used during the object's creation. If provided one must also include an `encryptionKey`. }
return string
    public function downloadAsString(array $options = [])
    {
        return (string) $this->downloadAsStream($options);
    }

Usage Example

 public function testDownloadsAsString()
 {
     $key = base64_encode('abcd');
     $hash = base64_encode('1234');
     $bucket = 'bucket';
     $object = 'object.txt';
     $stream = Psr7\stream_for($string = 'abcdefg');
     $this->connection->downloadObject(['bucket' => $bucket, 'object' => $object, 'generation' => null, 'httpOptions' => ['headers' => ['x-goog-encryption-algorithm' => 'AES256', 'x-goog-encryption-key' => $key, 'x-goog-encryption-key-sha256' => $hash]]])->willReturn($stream)->shouldBeCalledTimes(1);
     $object = new StorageObject($this->connection->reveal(), $object, $bucket);
     $this->assertEquals($string, $object->downloadAsString(['encryptionKey' => $key, 'encryptionKeySHA256' => $hash]));
 }
All Usage Examples Of Google\Cloud\Storage\StorageObject::downloadAsString