RackSpace CloudFiles - uploading files
To upload files into the CloudFiles storage you can use the SDK for PHP. Other programming languages are supported too. The full installation description is on the following page:
https://developer.rackspace.com/sdks/
I decided to keep playing with php. To install the php-opencloud SDK we use the composer utility:
composer require rackspace/php-opencloud
To install composer run the following command:
curl -sS https://getcomposer.org/installer | php
cp composer.phar /usr/local/bin/composer
If for some reason composer does not work for you - clone the git repository:
git clone https://github.com/rackspace/php-opencloud.git
Create the file upload.php in the current directory with the following content:
<?php
require 'vendor/autoload.php';
use OpenCloudRackspace;
$username='username';
$apiKey='api-key';
$region='datacenter region';
if( isset($argv[1]) && isset($argv[2])) {
$filename = $argv[1];
$containerName = $argv[2];
$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';
}
?>
You don’t need to mess with the token, the opencloud sdk does it all for you.
The script takes the name of the file you want to upload to the cloud, and the container name as the second argument.
Quickstart for Cloud Files
API operations for storage services