public function testContentType() { // Don't use the fixture, we want to test content // type in its raw state. $o = new Object('foo.txt'); $this->assertEquals('application/octet-stream', $o->contentType()); $o->setContentType('text/plain; charset=UTF-8'); $this->assertEquals('text/plain; charset=UTF-8', $o->contentType()); }
public function testSave() { // Clean up anything left. $this->destroyContainerFixture(); $container = $this->containerFixture(); $object = new Object(self::FNAME, self::FCONTENT, self::FTYPE); $object->setMetadata(['foo' => '1234']); $this->assertEquals(self::FCONTENT, $object->content()); try { $ret = $container->save($object); } catch (\Exception $e) { $this->destroyContainerFixture(); throw $e; } $this->assertTrue($ret); }
protected function createAnObject() { $container = $this->containerFixture(); $object = new Object(self::FNAME, self::FCONTENT, self::FTYPE); $object->setMetadata([self::FMETA_NAME => self::FMETA_VALUE]); $object->setDisposition(self::FDISPOSITION); $object->setEncoding(self::FENCODING); $object->setAdditionalHeaders(['Access-Control-Allow-Origin' => 'http://example.com', 'Access-control-allow-origin' => 'http://example.com']); // Need some headers that Swift actually stores and returns. This // one does not seem to be returned ever. //$object->setAdditionalHeaders(array(self::FCORS_NAME => self::FCORS_VALUE)); $container->save($object); }
/** * Copy an object to another place in object storage. * * An object can be copied within a container. Essentially, this will * give you duplicates of the file, each with a new name. * * An object can be copied to another container if the name of the * other container is specified, and if that container already exists. * * Note that there is no MOVE operation. You must copy and then DELETE * in order to achieve that. * * @param object $obj \OpenStack\ObjectStore\v1\Resource\Object The object to * copy. This object MUST already be saved on the remote server. The body of * the object is not sent. Instead, the copy operation is performed on the * remote server. You can, and probably should, use a RemoteObject here. * @param string $newName The new name of this object. If you are copying a * cross containers, the name can be the same. If you are copying within * the same container, though, you will need to supply a new name. * @param string $container The name of the alternate container. If this is * set, the object will be saved into this container. If this is not sent, * the copy will be performed inside of the original container. */ public function copy(Object $obj, $newName, $container = null) { $sourceUrl = self::objectUrl($this->url, $obj->name()); if (empty($newName)) { throw new Exception("An object name is required to copy the object."); } // Figure out what container we store in. if (empty($container)) { $container = $this->name; } $container = rawurlencode($container); $destUrl = self::objectUrl('/' . $container, $newName); $headers = ['X-Auth-Token' => $this->token, 'Destination' => $destUrl, 'Content-Type' => $obj->contentType()]; $response = $this->client->send($this->client->createRequest('COPY', $sourceUrl, null, ['headers' => $headers])); if ($response->getStatusCode() != 201) { throw new Exception("An unknown condition occurred during copy. " . $response->getStatusCode()); } return true; }
public function additionalHeaders($mergeAll = false) { // Any additional headers will be set. Note that $this->headers will contain // some headers that are NOT additional. But we do not know which headers are // additional and which are from Swift because Swift does not commit to using // a specific set of headers. if ($mergeAll) { $additionalHeaders = parent::additionalHeaders() + $this->allHeaders; $this->filterHeaders($additionalHeaders); } else { $additionalHeaders = parent::additionalHeaders(); } return $additionalHeaders; }