2010-05-04 23 views

Trả lời

0

Đây là mã của tôi trong C#. Chỉ cần đoán api là tương tự cho php.

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

Đảm bảo bạn đặt vùng chứa và xác định bất kỳ thư mục sudo nào bạn đang sử dụng.

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

Tôi nghĩ tôi sẽ đăng ở đây vì không có câu trả lời được đánh dấu là đúng, mặc dù tôi chấp nhận câu trả lời của Matthew Flaschen là câu trả lời chính xác. Đây sẽ là tất cả các mã bạn cần phải xoá bỏ tập tin của bạn

<?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") ; 
    } 

Note rằng "$ full_object_name" bao gồm "con đường" để các tập tin trong các container và các tên file không có ban đầu '/'. Điều này là do các thùng chứa sử dụng một thư mục/thư mục phân cấp Pseudo-thứ bậc và những gì kết thúc là tên của tệp trong vùng chứa là đường dẫn + tên tệp. để biết thêm thấy http://docs.rackspace.com/files/api/v1/cf-devguide/content/Pseudo-Hierarchical_Folders_Directories-d1e1580.html

0

Sử dụng phương pháp gọi là DeleteObject từ lớp CF_Container.

Phương thức DeleteObject của CF_Container chỉ yêu cầu một đối số chuỗi object_name. Đối số này phải là tên tệp cần xóa.

Xem ví dụ C# code dưới đây:

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

Note Đừng sử dụng DeleteObject từ lớp * CF_Client *

Các vấn đề liên quan