我正在尝试将Softlayer对象存储与我们的PHP应用程序集成。我正在使用https://github.com/softlayer/softlayer-object-storage-php中的API。
我有以下问题: -
请指教。感谢
答案 0 :(得分:0)
关于你的第一个问题: 看看以下链接:
关于第二个问题: 在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");