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

Upload an Archive to 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 upload a sample archive to the vault. 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 Upload method of the ArchiveTransferManager class to upload your archive. For small archives, this method uploads the archive directly to Amazon Glacier. For larger archives, this method uses Amazon Glacier's multipart upload API to split the upload into multiple parts for better error recovery, if any errors are encountered while streaming the data to Amazon Glacier.

For step-by-step instructions on how to run the following example, see Running Code Examples. You need to update the code as shown with the name of your vault and the name of the archive file to upload.

Note

Amazon Glacier keeps an inventory of all the archives in your vaults. When you upload the archive in the following example, it will not appear in a vault in the management console until the vault inventory has been updated. This update usually happens once a day.

Example — Uploading 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 ArchiveUploadHighLevel_GettingStarted { static string vaultName = "examplevault"; static string archiveToUpload = "*** Provide file name (with full path) to upload ***"; public static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); // Upload an archive. string archiveId = manager.Upload(vaultName, "getting started archive test", archiveToUpload).ArchiveId; Console.WriteLine("Copy and save the following Archive ID for the next step."); Console.WriteLine("Archive ID: {0}", archiveId); 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(); } } }