Softlayer对象存储元数据长度和文件夹大小

时间:2016-04-07 06:32:43

标签: ibm-cloud-infrastructure openstack-swift

我正在尝试将Softlayer对象存储与我们的PHP应用程序集成。我正在使用https://github.com/softlayer/softlayer-object-storage-php中的API。

我有以下问题: -

  1. 对象的自定义元数据的最大值长度是多少。我需要将有关对象的其他信息存储到元数据中。
  2. 如何获取文件夹大小而不是容器大小?我可以看到标题'X-container-bytes-used'用于容器大小。但是,需要获取文件夹大小。
  3. 请指教。感谢

1 个答案:

答案 0 :(得分:0)

关于你的第一个问题: 看看以下链接:

Constraints

关于第二个问题: 在Object Storage API v1 (SUPPORTED)进行一些研究,我没有找到任何方法来获取文件夹的大小。此外,Portal也不会显示文件夹大小。

解决方法是使用SoftLayer对象存储PHP客户端获取文件夹中的所有文件大小](https://github.com/softlayer/softlayer-object-storage-php

  

更新

获取文件夹大小的PHP脚本     

/**
 * 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");

参考文献: SoftLayer Object Storage PHP Client