How to access and upload files to folders on rackspace open cloud container using PHP?
I am using the 'rackspace / php-opencloud' composite package installed from
composer require rackspace/php-opencloud
and tries to download and list the files inside the folder
included the startup file and added
require 'vendor/autoload.php';
using the process outlined in the doc http://docs.php-opencloud.com/en/latest/services/object-store/index.html , but I don't get a solution for accessing folders inside the container (recipes in my case). How can I upload files to the "images" directory and "upload" to the containers "recipes".
$client = new OpenCloud\OpenStack('{keystoneUrl}', array(
'username' => '{username}',
'password' => '{apiKey}',
'tenantId' => '{tenantId}',
));
$service = $client->objectStoreService('{catalogName}', '{region}', '{urlType}');
$ container = $ service-> listContainers ();
foreach ($containers as $container) {
/** @param $container OpenCloud\ObjectStore\Resource\Container */
printf("Container name: %s\n", $container->name);
printf("Number of objects within container: %d\n", $container->getObjectCount());
}
In the above code, I can access the list of containers and I can set the container and get the list
$containers = $service->listContainers();
** @param $container OpenCloud\ObjectStore\Resource\Container */
$container = $service->getContainer('{containerName}');
source to share
I found the answer on the rackspace website: https://developer.rackspace.com/docs/cloud-files/quickstart/?lang=php
And they clearly explain that we cannot create a new container inside any container that we can pass to a subdirectory and then pass the object name as described below:
While you cannot create nested containers, cloud files support subdirectories or subfolders. Objects are loaded into a subdirectory using a special naming convention, including the subdirectory path in the object name, separating path segments with the forward slash character /.
For example, if you want the relative url of the object to be /images/kittens/thumbnails/kitty.png, load the object into the container using that relative path as the object name
$object = $container->uploadObject('{subdirectories}/{object_name}', $handle);
source to share