/** * Update an object's metadata. * * This updates the metadata on an object without modifying anything * else. This is a convenient way to set additional metadata without * having to re-upload a potentially large object. * * Swift's behavior during this operation is sometimes unpredictable, * particularly in cases where custom headers have been set. * Use with caution. * * @param object $obj \OpenStack\ObjectStore\v1\Resource\Object The object to update. * * @return boolean true if the metadata was updated. * * @throws \OpenStack\Common\Transport\Exception\ResourceNotFoundException if the object does not already * exist on the object storage. */ public function updateMetadata(Object $obj) { $url = self::objectUrl($this->url, $obj->name()); $headers = ['X-Auth-Token' => $this->token]; // See if we have any metadata. We post this even if there // is no metadata. $metadata = $obj->metadata(); if (!empty($metadata)) { $headers += self::generateMetadataHeaders($metadata, Container::METADATA_HEADER_PREFIX); } // In spite of the documentation's claim to the contrary, // content type IS reset during this operation. $headers['Content-Type'] = $obj->contentType(); // The POST verb is for updating headers. $response = $this->client->post($url, $obj->content(), ['headers' => $headers]); if ($response->getStatusCode() != 202) { throw new Exception(sprintf("An unknown error occurred while saving: %d", $response->status())); } return true; }