Skip to content

Instantly share code, notes, and snippets.

@nickweavers
Last active August 29, 2015 13:58
Show Gist options
  • Save nickweavers/9939652 to your computer and use it in GitHub Desktop.
Save nickweavers/9939652 to your computer and use it in GitHub Desktop.
A Joomla model that gets a file from RackSpace's cloud
function getFile($id_file) {
$fileRecord = $this->getFileRecord($id_file);
$client = new Rackspace(Rackspace::UK_IDENTITY_ENDPOINT, array( // Note the use of
'username' => USER,
'apiKey' => PSWD
));
// Create a service object to use the object store service. We give it the region name on LON (For London) as this is where are server and cloud files are
$service = $client->objectStoreService('cloudFiles', 'LON');
// get the document name from the database
$docType = $this->getDocType($fileRecord->id_doctype);
$container_name = "ddfs_factfinder_{$fileRecord->id_factfind}:{$docType->name}";
try {
// If container already exists
$container = $service->getContainer($container_name);
} catch (Guzzle\Http\Exception\ClientErrorResponseException $e) {
// If the container doesn't exist...
$error_msg = "Container wasn't found.";
throw new Exception($error_msg);
}
$file = $container->getObject($file->file_name);
$doc = new stdClass();
$doc->name = $fileRecord->file_name;
$doc->content_type = $file->getContentType();
$doc->content_body = $file->getContent();
return $doc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment