我想知道如何使用他们的 API 从 Rackspace 的 Cloudfiles 中删除文件?
我正在使用 php。
德万
使用 CF_Container 的delete_object方法。
确保设置容器并定义您正在使用的任何 sudo 文件夹。
$my_container = $this->conn->get_container($cf_container);
//delete file
$my_container->delete_object($cf_folder.$file_name);
这是我在 C# 中的代码。只是猜测 api 与 php 类似。
UserCredentials userCredientials = new UserCredentials("xxxxxx", "99999999999999");
cloudConnection = new Connection(userCredientials);
cloudConnection.DeleteStorageItem(ContainerName, fileName);
我想我会在这里发帖,因为没有标记为正确的答案,尽管我会接受 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
使用类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