/** * @return mixed */ public function build() { $mime = $this->object->getContentType(); if (isset($this->elementMap[$mime])) { $elementClass = $this->elementMap[$mime]; } elseif (false !== ($element = $this->searchWildcards($mime))) { $elementClass = $element; } else { $elementClass = self::DEFAULT_ELEMENT_CLASS; } $elementClass = __NAMESPACE__ . '\\HtmlElement\\' . $elementClass; return $elementClass::factory($this->renderer, $this->object, $this->urlType, $this->attributes); }
/** * {@inheritdoc} */ protected function normalizeObject(DataObject $object) { $name = $object->getName(); $name = $this->removePathPrefix($name); $mimetype = explode('; ', $object->getContentType()); return ['type' => in_array('application/directory', $mimetype) ? 'dir' : 'file', 'dirname' => Util::dirname($name), 'path' => $name, 'timestamp' => strtotime($object->getLastModified()), 'mimetype' => reset($mimetype), 'size' => $object->getContentLength()]; }
public function touch($path, $mtime = null) { $path = $this->normalizePath($path); if (is_null($mtime)) { $mtime = time(); } $metadata = array('timestamp' => $mtime); if ($this->file_exists($path)) { if ($this->is_dir($path) && $path != '.') { $path .= '/'; } $object = $this->fetchObject($path); if ($object->saveMetadata($metadata)) { // invalidate target object to force repopulation on fetch $this->objectCache->remove($path); } return true; } else { $mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path); $customHeaders = array('content-type' => $mimeType); $metadataHeaders = DataObject::stockHeaders($metadata); $allHeaders = $customHeaders + $metadataHeaders; $this->getContainer()->uploadObject($path, '', $allHeaders); // invalidate target object to force repopulation on fetch $this->objectCache->remove($path); return true; } }
public function touch($path, $mtime = null) { $path = $this->normalizePath($path); if (is_null($mtime)) { $mtime = time(); } $metadata = array('timestamp' => $mtime); if ($this->file_exists($path)) { if ($this->is_dir($path) && $path != '.') { $path .= '/'; } $object = $this->container->getPartialObject($path); $object->saveMetadata($metadata); return true; } else { $customHeaders = array('content-type' => 'text/plain'); $metadataHeaders = DataObject::stockHeaders($metadata); $allHeaders = $customHeaders + $metadataHeaders; $this->container->uploadObject($path, '', $allHeaders); return true; } }
/** * Copies the object to another container/object * * Note that this function, because it operates within the Object Store * itself, is much faster than downloading the object and re-uploading it * to a new object. * * @param DataObject $target the target of the COPY command */ public function copy(DataObject $target) { $uri = sprintf('/%s/%s', $target->container()->name(), $target->name()); $this->getLogger()->info('Copying object to [{uri}]', array('uri' => $uri)); $response = $this->getService()->request($this->url(), 'COPY', array('Destination' => $uri)); // check response code // @codeCoverageIgnoreStart if ($response->httpStatus() > 202) { throw new Exceptions\ObjectCopyError(sprintf(Lang::translate('Error copying object [%s], status [%d] response [%s]'), $this->url(), $response->httpStatus(), $response->httpBody())); } // @codeCoverageIgnoreEnd return $response; }
/** * Normalize a DataObject * * @param DataObject $object * @return array file metadata */ protected function normalizeObject(DataObject $object) { $name = $object->getName(); if ($this->prefix) { $name = substr($name, strlen($this->prefix)); } $mimetype = explode('; ', $object->getContentType()); return array('type' => 'file', 'dirname' => Util::dirname($name), 'path' => $name, 'timestamp' => strtotime($object->getLastModified()), 'mimetype' => reset($mimetype), 'size' => $object->getContentLength()); }
public function touch($path, $mtime = null) { $path = $this->normalizePath($path); if (is_null($mtime)) { $mtime = time(); } $metadata = array('timestamp' => $mtime); if ($this->file_exists($path)) { $object = $this->getContainer()->getPartialObject($path); $object->saveMetadata($metadata); return true; } else { $mimeType = \OC_Helper::getMimetypeDetector()->detectPath($path); $customHeaders = array('content-type' => $mimeType); $metadataHeaders = DataObject::stockHeaders($metadata); $allHeaders = $customHeaders + $metadataHeaders; $this->getContainer()->uploadObject($path, '', $allHeaders); return true; } }
* limitations under the License. */ // // Pre-requisites: // * Prior to running this script, you must setup the following environment variables: // * RAX_USERNAME: Your Rackspace Cloud Account Username, and // * RAX_API_KEY: Your Rackspace Cloud Account API Key // * There exists a container named 'logos' in your Object Store. Run // create-container.php if you need to create one first. // require __DIR__ . '/../../vendor/autoload.php'; use OpenCloud\Rackspace; use OpenCloud\ObjectStore\Resource\DataObject; // 1. Instantiate a Rackspace client. $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => getenv('RAX_USERNAME'), 'apiKey' => getenv('RAX_API_KEY'))); // 2. Obtain an Object Store service object from the client. $region = 'DFW'; $objectStoreService = $client->objectStoreService(null, $region); // 3. Get container. $container = $objectStoreService->getContainer('logos'); // 4. Upload an object to the container. $localFileName = __DIR__ . '/php-elephant.jpg'; $remoteFileName = 'php-elephant.jpg'; $metadata = array('author' => 'Jane Doe'); $customHeaders = array(); $metadataHeaders = DataObject::stockHeaders($metadata); $allHeaders = $customHeaders + $metadataHeaders; $fileData = fopen($localFileName, 'r'); $container->uploadObject($remoteFileName, $fileData, $allHeaders); // Note that while we call fopen to open the file resource, we do not call fclose at the end. // The file resource is automatically closed inside the uploadObject call.
public function upload_object($file_name, $file_location, array $meta_data = array()) { $data = fopen($file_location . $file_name, 'r+'); $metaHeaders = DataObject::stockHeaders($meta_data); $this->container->uploadObject($this->virtual_folder . $file_name, $data, $metaHeaders); log_message('debug', 'Rackspace Cloudfiles: File ' . $this->virtual_folder . $file_name . ' was uploaded'); }
/** * @param DataObject $object * @param bool $includeContent * * @return File */ private function generateFileFromDataObject(DataObject $object, $includeContent = true) { $file = new File(); if ($includeContent) { $file->content = $object->getContent(); } $file->mime = $object->getContentType(); $chunks = explode('/', $object->getName()); $file->name = array_pop($chunks); $file->size = $object->getContentLength(); return $file; }
function upload_data($authuserid) { $username = "******"; // username $key = "0d5739ba0696428f885890282d3ba150"; // api key //Rackspace client $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => $username, 'apiKey' => $key)); //Authenticate client $client->authenticate(); $service = $client->objectStoreService('cloudFiles'); $container = $service->getContainer('userimages'); //Figure out the user first name and last name based on the $name variable //We must have got some dimensions to crop the images, lets get that set $profile_image_crop_x = $_POST['x']; $profile_image_crop_y = $_POST['y']; $profile_image_crop_w = $_POST['w']; $profile_image_crop_h = $_POST['h']; if ($_FILES['profile_image']['tmp_name'] != "") { $imageProcessor = new ImageManipulator($_FILES['profile_image']['tmp_name']); if ($profile_image_crop_w > 1 && $profile_image_crop_h > 1) { $croppedImage = $imageProcessor . crop($profile_image_crop_x, $profile_image_crop_y, $profile_image_crop_x + $profile_image_crop_w, $profile_image_crop_y + $profile_image_crop_h); } $imageProcessor->save($basePath . $target_profile_pic_name); //Read back the file so that we can now upload it to Rackspace CDN. //Common Meta $meta = array('Author' => $name, 'Origin' => 'FINAO Web'); $metaHeaders = DataObject::stockHeaders($meta); $data = fopen($basePath . $target_profile_pic_name, 'r+'); $container->uploadObject($target_profile_pic_name, $data, $metaHeaders); $targ_w = 150; $targ_h = 150; $jpeg_quality = 90; $profile_thumb_image = $imageProcessor->resample($targ_w, $targ_h); $imageProcessor->save($basePath . $target_profile_pic_thumb); $data = fopen($basePath . $target_profile_pic_thumb, 'r+'); $container->uploadObject($target_profile_pic_thumb, $data, $metaHeaders); } if ($_FILES['profile_bg_image']['tmp_name'] != "") { @move_uploaded_file($_FILES['profile_bg_image']['tmp_name'], 'images/uploads/profileimages/' . $target_banner_pic_name); //Common Meta $meta = array('Author' => $name, 'Origin' => 'FINAO Web'); $metaHeaders = DataObject::stockHeaders($meta); $data = fopen($basePath . $target_banner_pic_name, 'r+'); $container->uploadObject($target_banner_pic_name, $data, $metaHeaders); } }