Reputation: 4315
I am using composer package 'rackspace/php-opencloud' installed with
composer require rackspace/php-opencloud
and trying to upload and get the list of files inside the folder
included the autoload file and add
require 'vendor/autoload.php';
using the process given on document http://docs.php-opencloud.com/en/latest/services/object-store/index.html but I do not get the solution to access the folders inside a container(recipes in my case). How can I upload the files into the directory "images" and "uploads" present inside container "recipes".
$client = new OpenCloud\OpenStack('{keystoneUrl}', array(
'username' => '{username}',
'password' => '{apiKey}',
'tenantId' => '{tenantId}',
));
$service = $client->objectStoreService('{catalogName}', '{region}', '{urlType}');
$containers = $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());
}
By the above code, I am able to access the the list of container and I can set the container and can fetch the list of
$containers = $service->listContainers();
** @param $container OpenCloud\ObjectStore\Resource\Container */
$container = $service->getContainer('{containerName}');
Upvotes: 3
Views: 654
Reputation: 4315
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 new container inside any container we can pass subdirectory then pass name of the object like explained below:
While you cannot create nested containers, Cloud Files does support subdirectories, or subfolders. Objects are uploaded to a subdirectory through a special naming convention, by 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, upload the object to a container using that relative path as the object name
$object = $container->uploadObject('{subdirectories}/{object_name}', $handle);
Upvotes: 5