如何使用 Rackspace 的 API 从 Cloudfiles 中删除文件?

发布于 2024-08-31 09:03:26 字数 81 浏览 6 评论 0原文

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

我正在使用 php。

德万

I was wondering how do i remove a file from Rackspace's Cloudfiles using their API?

Im using php.

Devan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

墨离汐 2024-09-07 09:03:26

使用 delete_object 方法CF_Container 的。

Use the delete_object method of CF_Container.

雪化雨蝶 2024-09-07 09:03:26

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

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

Here is my code in C#. Just guessing the api is similar for php.

    UserCredentials userCredientials = new UserCredentials("xxxxxx", "99999999999999");
    cloudConnection = new Connection(userCredientials);
    cloudConnection.DeleteStorageItem(ContainerName, fileName);
甜味拾荒者 2024-09-07 09:03:26

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

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

Make sure you set the container and define any sudo folder you are using.

$my_container = $this->conn->get_container($cf_container);
//delete file
$my_container->delete_object($cf_folder.$file_name);
一个人的旅程 2024-09-07 09:03:26

我想我应该在这里发帖,因为没有一个答案被标记为正确的答案,尽管我会接受马修·弗拉申的答案作为正确的答案。这将是删除文件所需的全部代码

<?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

I thought I would post here since there isn't an answer marked as the correct one, although I would accept Matthew Flaschen answer as the correct one. This would be all the code you need to delete your file

<?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 that the "$full_object_name" includes the "path" to the file in the container and the file name with no initial '/'. This is because containers use a Pseudo-Hierarchical folders/directories and what end ups being the name of the file in the container is the path + filename. for more info see http://docs.rackspace.com/files/api/v1/cf-devguide/content/Pseudo-Hierarchical_Folders_Directories-d1e1580.html

于我来说 2024-09-07 09:03:26

使用 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

Use the method called DeleteObject from class CF_Container.

The method DeleteObject of CF_Container require only one string argument object_name.
This arguments should be the filename to be deleted.

See the example C# code bellow:

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 Don´t use the DeleteObject from class *CF_Client*

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文