本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用从 S3 Gacier 中的文件库下载档案Amazon SDK for .NET
以下 C# 代码示例使用高级 APIAmazon SDK for .NET下载您之前在中上传的档案使用在中将档案上传到 S3 Glacier 中的文件库Amazon SDK for .NET. 在代码示例中,请注意以下情况:
-
此示例创建
ArchiveTransferManager
指定的 Amazon S3 Glacier 区域终端节点的类。 -
此代码示例使用美国西部(俄勒冈)区域(
us-west-2
) 匹配您之前在中创建文件库的位置步骤 2:在 S3 Glacier 中创建文件库. -
此示例使用
Download
的 API 操作ArchiveTransferManager
类来下载档案。此示例创建Amazon Simple Notification Service (Amazon SNS) 主题和订阅该主题的 Amazon SQS 队列。如果你创建了一个Amazon Identity and Access Management(IAM) 管理员用户步骤 1:在开始使用 S3 Glacier 之前,则您的用户具有必要的 IAM 权限以创建和使用 Amazon SNS 主题和 Amazon SQS 队列。 -
此示例启动了存档检索任务,并对队列进行轮询以便找到可用存档。如果存档可用,则开始下载。有关检索时间的详细信息,请参阅 档案检索选项。
适用于 step-by-step 有关运行方法的说明,请参阅运行代码示例. 您必须更新中已上传文件的档案 ID 旁显示的代码步骤 3:将档案上传到 S3 Glacier 中的文件库.
例 — 使用高级 API 下载档案Amazon SDK for .NET
using System; using Amazon.Glacier; using Amazon.Glacier.Transfer; using Amazon.Runtime; namespace glacier.amazon.com.docsamples { class ArchiveDownloadHighLevel_GettingStarted { static string vaultName = "examplevault"; static string archiveId = "*** Provide archive ID ***"; static string downloadFilePath = "*** Provide the file name and path to where to store the download ***"; public static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); var options = new DownloadOptions(); options.StreamTransferProgress += ArchiveDownloadHighLevel_GettingStarted.progress; // Download an archive. Console.WriteLine("Intiating the archive retrieval job and then polling SQS queue for the archive to be available."); Console.WriteLine("Once the archive is available, downloading will begin."); manager.Download(vaultName, archiveId, downloadFilePath, options); Console.WriteLine("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 int currentPercentage = -1; static void progress(object sender, StreamTransferProgressArgs args) { if (args.PercentDone != currentPercentage) { currentPercentage = args.PercentDone; Console.WriteLine("Downloaded {0}%", args.PercentDone); } } } }