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

update() public method

Example: Add custom metadata to an existing object. $object->update([ 'metadata' => [ 'albumType' => 'family' ] ]);
See also: https://cloud.google.com/storage/docs/json_api/v1/objects/patch Objects patch API documentation.
public update ( array $metadata, array $options = [] ) : array
$metadata array The available options for metadata are outlined at the [JSON API docs](https://cloud.google.com/storage/docs/json_api/v1/objects#resource)
$options array [optional] { Configuration options. @type string $ifGenerationMatch Makes the operation conditional on whether the object's current generation matches the given value. @type string $ifGenerationNotMatch Makes the operation conditional on whether the object's current generation does not match the given value. @type string $ifMetagenerationMatch Makes the operation conditional on whether the object's current metageneration matches the given value. @type string $ifMetagenerationNotMatch Makes the operation conditional on whether the object's current metageneration does not match the given value. @type string $predefinedAcl Apply a predefined set of access controls to this object. @type string $projection Determines which properties to return. May be either 'full' or 'noAcl'. @type string $fields Selector which will cause the response to only return the specified fields. }
return array
    public function update(array $metadata, array $options = [])
    {
        $options += $metadata;
        return $this->info = $this->connection->patchObject($options + $this->identity);
    }

Usage Example

 public function testUpdatesData()
 {
     $data = ['contentType' => 'image/jpg'];
     $this->connection->patchObject(Argument::any())->willReturn(['name' => 'object.txt'] + $data);
     $object = new StorageObject($this->connection->reveal(), 'object.txt', 'bucket', null, ['contentType' => 'image/png']);
     $object->update($data);
     $this->assertEquals($data['contentType'], $object->info()['contentType']);
 }