2010-05-04 49 views

回答

0

這是我在C#中的代碼。只是猜測的API是相似的PHP。

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

確保您設置容器並定義您正在使用的任何sudo文件夾。

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

我想我會在這裏發佈,因爲沒有標記爲一個正確的答案,但我會接受馬修•富蘭琛答案正確的。這將是所有你需要刪除的文件

<?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」包括「路徑」,以在容器中的文件,並沒有最初的「/」的文件名中的代碼。這是因爲容器使用僞分層文件夾/目錄以及容器中文件的名稱是路徑+文件名。更多信息請參見http://docs.rackspace.com/files/api/v1/cf-devguide/content/Pseudo-Hierarchical_Folders_Directories-d1e1580.html

0

類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); 

注意鴕鳥政策使用DeleteObject的從類* CF_Client *

相關問題