0

I'm trying to integrate Softlayer Object Storage with our PHP Application. Im using API from https://github.com/softlayer/softlayer-object-storage-php.

I have following queries :-

  1. What is Maximum value length for Object's custom Metadata. I needed to store some additional info about object into metadata.
  2. How to get the folder size rather than container size? I can see header 'X-container-bytes-used' which for container size. But, need to get for folder size.

Please advice. Thanks

1 Answers1

0

For your first question: Take a look the following link:

Constraints

For the second question: Doing a little research in Object Storage API v1 (SUPPORTED), I didn't find any way to get the folder's size. Also the Portal doesn't display the folder size neither.

A workaround would be to get all the file's sizes inside the folder using SoftLayer Object Storage PHP Client](https://github.com/softlayer/softlayer-object-storage-php)

Updated

PHP Script to get folder size

/**
 * This method retrieves folder size
 * @var $containerName - The container's name where the folder is located
 * @var $folder - The folder that you wish to retrieve its size
 */
function getFolderSize($objectStorage, $containerName, $folder) {
    // Get objects
    $objects = $objectStorage -> with($containerName . "/") -> get() -> objects;
    $size = 0;
    foreach ($objects as $object) {
        $objectName = explode($containerName . "/", $object -> getPath());
        $folderName = explode($folder . "/", $objectName[1]);
        if (sizeof($folderName) > 1) {
            $sizeObject = $objectStorage -> with($containerName . "/" . $folder . "/" . $folderName[1]) -> get() -> getHeader('Content-length');
            $size = $size + $sizeObject;
            //print_r("\n File" . $folderName[1] . "   " . $sizeObject . " Bytes (" . ($sizeObject / 1024) . " KB)       Total Size Folder: " . $size . " Bytes (" . ($size / 1024) . " KB)");
        }
    }
    return $size;
}

/**
 * Declare Object Storage parameters
 */
$host = 'https://mil01.objectstorage.softlayer.net/auth/v1.0/';
// the SoftLayer Object Storage API host
$username = 'set me';
$password = 'set me';
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);

/**
 * Creating Object Storage Object
 */
$objectStorage = new ObjectStorage($host, $username, $password, $options);

/**
 * Retrieve a folder's size
 */
$size = getFolderSize($objectStorage, "rcvTest", "folderTest/folder1/subfolder1/subsubfolder1");
print_r("\n Folde Size: " . $size . " bytes   " . $size / 1024 . " KB");

References: SoftLayer Object Storage PHP Client

  • Thanks for the answer @RuberCuellar. I'm clear on the constraints now. :) But, on getting folder size still doesn't help much. I already using SoftLayer Object Storage PHP Client as i mentioned earlier. Only way that i can think of is counting content length of every files inside folder & its subfolder recursively. :( – Saravanan Sivam Apr 08 '16 at 07:11
  • Let me see... I will try to verify with the PHP client if there exists any way to get folder size, I will let you know any news – Ruber Cuellar Valenzuela Apr 08 '16 at 13:58
  • I couldn't find any way to get the folder size in a single call. BTW I attached a script using PHP Object Storage Client to get folder size. It takes the objects or subfolders which can be inside from the folder that you want to get the size. It makes several calls to get size from each object inside the folder. It can be improved. I hope it helps. – Ruber Cuellar Valenzuela Apr 08 '16 at 21:43
  • Thanks @Ruber Cuellar :) – Saravanan Sivam May 05 '16 at 05:14