如果您不熟悉 Amazon Simple Storage Service (Amazon S3) 中的归档存储功能,建议您先详细了解 Amazon S3 中的 S3 Glacier 存储类、S3 Glacier 即时检索、S3 Glacier 灵活检索和 S3 Glacier 深度归档。有关更多信息,请参阅 Amazon S3 用户指南中的 S3 Glacier 存储类
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Amazon SDK for .NET 在 Amazon S3 Glacier 中删除档案
适用于 .NET 的 Amazon SDK 提供的高级和低级 API 都提供了删除档案的方法。
使用Amazon SDK for .NET高级 API 删除档案
该高级 API 的 ArchiveTransferManager
类提供了您可以用来删除档案的 DeleteArchive
方法。
示例:使用Amazon SDK for .NET高级 API 删除档案
以下 C# 代码示例使用Amazon SDK for .NET高级 API 来删除档案。有关如何运行以下示例的分步说明,请参阅运行代码示例。您需要更新待删除档案 ID 旁显示的代码。
using System; using Amazon.Glacier; using Amazon.Glacier.Transfer; using Amazon.Runtime; namespace glacier.amazon.com.docsamples { class ArchiveDeleteHighLevel { static string vaultName = "examplevault"; static string archiveId = "*** Provide archive ID ***"; public static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); manager.DeleteArchive(vaultName, archiveId); Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } } }
使用Amazon SDK for .NET低级 API 删除档案
以下是使用Amazon SDK for .NET删除档案的步骤。
-
创建
AmazonGlacierClient
类(客户端)的实例。您需要指定存储您要删除的档案的 Amazon 区域。您使用此客户端执行的所有操作都会应用到该 Amazon 区域。
-
通过创建一个
DeleteArchiveRequest
类的实例提供请求信息。您需要提供档案 ID、文件库名称和您的账户 ID。如果您不提供账户 ID,则系统会使用与您提供来对请求签名的证书相关联的账户 ID。有关更多信息,请参阅将 Amazon SDK 与 Amazon S3 Glacier 结合使用。
-
以参数形式提供请求对象,运行
DeleteArchive
方法。
示例:使用Amazon SDK for .NET低级 API 删除档案
以下 C# 示例说明了前面的步骤。该示例使用 Amazon SDK for .NET 的低级 API 删除档案。
注意
有关底层 REST API 的信息,请参阅删除档案。
有关如何运行以下示例的分步说明,请参阅运行代码示例。您需要更新待删除档案 ID 旁显示的代码。
using System; using Amazon.Glacier; using Amazon.Glacier.Model; using Amazon.Runtime; namespace glacier.amazon.com.docsamples { class ArchiveDeleteLowLevel { static string vaultName = "examplevault"; static string archiveId = "*** Provide archive ID ***"; public static void Main(string[] args) { AmazonGlacierClient client; try { using (client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2)) { Console.WriteLine("Deleting the archive"); DeleteAnArchive(client); } Console.WriteLine("Operations successful. To continue, press Enter"); Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } static void DeleteAnArchive(AmazonGlacierClient client) { DeleteArchiveRequest request = new DeleteArchiveRequest() { VaultName = vaultName, ArchiveId = archiveId }; DeleteArchiveResponse response = client.DeleteArchive(request); } } }