Upload data to RackSpace CloudFIles

‘CloudFIles’ is one of the services in the list of RackSpace cloud. You can use it to locate some of the files you need. RackSpace provides SDK that can be used to work with their cloud services. I’ll review the example in PHP however other programming languages are supported too.

The complete list is available on the following page:

Let’s install SDK php-opencloud with the help of composer:

composer require rackspace/php-opencloud

Create the upload.php file in the current folder with the following code in it:

require 'vendor/autoload.php';
use OpenCloud\Rackspace;

$region='datacenter region';
$containerName='container name'

if( isset($argv[1])) {
   $filename  = $argv[1];

   $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
      'username' => $username,
      'apiKey'   => $apiKey,

   $objectStoreService = $client->objectStoreService(null, $region);
   $container = $objectStoreService->getContainer($containerName);

   $handle = fopen($filename, 'r');
   $object = $container->uploadObject($filename, $handle);
} else { 
   echo 'No files provided' 

There is no need to get token, because ‘opencloud sdk’ will do this for you.

The script takes a file name as an argument. This file will be uploaded into the container.

You need to create the container frist. The Api-Key and datacenter region can be obtained from your cloud account.

Quickstart for Cloud Files
API operations for storage services

Share Button

Leave a Reply

You must be logged in to post a comment.