如何使用laravel-rackspace-opencloud创建/删除容器?

时间:2014-10-23 10:59:23

标签: laravel-4 rackspace-cloudfiles php-opencloud

我正在使用laravel-rackspace-opencloud包来管理RackSpace的云文件平台上的文件。是否可以使用此库来创建/删除文件容器?我无法找到这样的例子,README似乎只引用了已经创建的容器内的文件管理。

1 个答案:

答案 0 :(得分:1)

  

请按照步骤创建/删除文件容器

  1. 使用laravel创建机架空间文件容器

    $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array( 
           'username' => 'XXXXXX','apiKey'   => 'XXXXXX'));
    
    try{
       $ContainerName = 'todo'; // static for now
       $objectStoreService = $client->objectStoreService(null, 'DFW');
       $container = $objectStoreService->createContainer($ContainerName);
    
    } catch (Guzzle\Http\Exception\ClientErrorResponseException $e) {
        Log::info($e->getResponse());
    }
    
  2.   
        
    1. 删除容器
    2.   
      //1. conneciton
      $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(   
               'username' => 'XXXXXX','apiKey'   => 'XXXXXX'));
    
      // 2. get region
      $objectStoreService = $client->objectStoreService(null, 'DFW');
    
      // 3. Get container.
      $container = $objectStoreService->getContainer('{containerName}');
      // 4. Delete container.
      $container->delete();