Menu
Amazon Glacier
Developer Guide (API Version 2012-06-01)

Download an Archive from a Vault in Amazon Glacier Using the AWS SDK for .NET

The following C# code example uses the high-level API of the AWS SDK for .NET to download the archive you uploaded previously in Upload an Archive to a Vault in Amazon Glacier Using the AWS SDK for .NET. In the code example, note the following:

  • The example creates an instance of the ArchiveTransferManager class for the specified Amazon Glacier region endpoint.

  • The code example uses the US West (Oregon) region (us-west-2) to match the location where you created the vault previously in Step 2: Create a Vault in Amazon Glacier.

  • The example uses the Download method of the ArchiveTransferManager class to upload your archive. The Download method creates an Amazon SNS topic, and an Amazon SQS queue that is subscribed to that topic. It then initiates the archive retrieval job and polls the queue for the archive to be available. This polling takes about 4 hours. Once the archive is available, download will begin.

For step-by-step instructions on how to run this example, see Running Code Examples. You need to update the code as shown with the archive ID of the file you uploaded in Step 3: Upload an Archive to a Vault in Amazon Glacier.

Example — Download an Archive Using the High-Level API of the AWS SDK for .NET

Copy
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("This polling takes about 4 hours. 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); } } } }