API を使用して Rackspace の Cloudfiles からファイルを削除するにはどうすればよいですか?
私はphpを使用しています。
デヴァン
CF_Containerのdelete_objectメソッドを使用します。
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」には、コンテナ内のファイルへの「パス」と、最初の「/」がないファイル名が含まれていることに注意してください。これは、コンテナーが疑似階層フォルダー/ディレクトリーを使用し、最終的にコンテナー内のファイルの名前がパス+ファイル名になるためです。詳細については、http://docs.rackspace.com/files/api/v1/cf-devguide/content/Pseudo-Hierarchical_Folders_Directories-d1e1580.htmlを参照してください。
クラスCF_ContainerのDeleteObjectというメソッドを使用します。
CF_Container のメソッド DeleteObject には、文字列引数object_nameが 1 つだけ必要です。この引数は、削除するファイル名でなければなりません。
以下の 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を使用しないでください
これがC#の私のコードです。APIがphpと似ていると推測するだけです。
UserCredentials userCredientials = new UserCredentials("xxxxxx", "99999999999999");
cloudConnection = new Connection(userCredientials);
cloudConnection.DeleteStorageItem(ContainerName, fileName);
コンテナーを設定し、使用している sudo フォルダーを定義していることを確認してください。
$my_container = $this->conn->get_container($cf_container);
//delete file
$my_container->delete_object($cf_folder.$file_name);