How to delete a file from Rackspace Cloudfiles using api?

I was wondering how to remove a file from Rackspace Cloudfiles using their APIs?

Im using php.

Devan

+5
source share
5 answers

Use the delete_object method for CF_Container.

+3
source

Here is my C # code. Just guessing the api is like php.

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

, 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

DeleteObject CF_Container.

The DeleteObject method for CF_Container requires only one string argument object_name . This argument must be the name of the file to be deleted.

See sample C # code below:

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 Do not use the DeleteObject from the * CF_Client * class

0
source

All Articles