【问题标题】:How do i remove a file from Rackspace's Cloudfiles with their api?如何使用他们的 api 从 Rackspace 的 Cloudfiles 中删除文件?
【发布时间】:2011-02-15 17:10:57
【问题描述】:

我想知道如何使用他们的 API 从 Rackspace 的 Cloudfiles 中删除文件?

我正在使用 php。

德文

【问题讨论】:

    标签: php file rackspace upload


    【解决方案1】:

    使用 CF_Container 的delete_object 方法。

    【讨论】:

      【解决方案2】:

      这是我的 C# 代码。只是猜测 api 与 php 类似。

          UserCredentials userCredientials = new UserCredentials("xxxxxx", "99999999999999");
          cloudConnection = new Connection(userCredientials);
          cloudConnection.DeleteStorageItem(ContainerName, fileName);
      

      【讨论】:

        【解决方案3】:

        确保您设置了容器并定义了您正在使用的任何 sudo 文件夹。

        $my_container = $this->conn->get_container($cf_container);
        //delete file
        $my_container->delete_object($cf_folder.$file_name);
        

        【讨论】:

          【解决方案4】:

          我想我会在这里发帖,因为没有标记为正确的答案,尽管我会接受 Matthew Flaschen 的答案作为正确的答案。这就是删除文件所需的所有代码

          <?php
              require '/path/to/php-cloudfiles/cloudfiles.php';
          
              $username = 'my_username';
              $api_key = 'my_api_key';
              $full_object_name = 'this/is/the/full/file/name/in/the/container.png';
          
              $auth = new CF_Authentication($username, $api_key);
              $auth->ssl_use_cabundle();
              $auth->authenticate();
          
              if ( $auth->authenticated() )
              {
                  $this->connection = new CF_Connection($auth);
          
                  // Get the container we want to use
                  $container = $this->connection->get_container($name);
                  $object = $container->delete_object($full_object_name);
                  echo 'object deleted';
              }
              else
              {
                  throw new AuthenticationException("Authentication failed") ;
              }
          

          注意“$full_object_name”包括容器中文件的“路径”和不带首字母“/”的文件名。这是因为容器使用 Pseudo-Hierarchical 文件夹/目录,最终容器中的文件名是路径 + 文件名。欲了解更多信息,请参阅http://docs.rackspace.com/files/api/v1/cf-devguide/content/Pseudo-Hierarchical_Folders_Directories-d1e1580.html

          【讨论】:

            【解决方案5】:

            使用 CF_Container 类中名为 DeleteObject 的方法。

            CF_Container 的DeleteObject 方法只需要一个字符串参数object_name。 这个参数应该是要删除的文件名。

            请参阅下面的示例 C# 代码:

            string username = "your-username";
            string apiKey = "your-api-key";
            
            CF_Client client = new CF_Client();
            UserCredentials creds = new UserCredentials(username, apiKey);
            Connection conn = new CF_Connection(creds, client);
            
            conn.Authenticate();
            
            
            var containerObj = new CF_Container(conn, client, container);
            
            string file = "filename-to-delete";
            containerObj.DeleteObject(file);
            

            注意不要使用 *CF_Client* 类中的 DeleteObject

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2018-07-20
              • 1970-01-01
              • 2013-07-18
              相关资源
              最近更新 更多