Upload an Archive to a Vault in S3 Glacier by Using the AWS SDK for .NET - Amazon S3 Glacier

If you're new to archival storage in Amazon Simple Storage Service (Amazon S3), we recommend that you start by learning more about the S3 Glacier storage classes in Amazon S3, S3 Glacier Instant Retrieval, S3 Glacier Flexible Retrieval, and S3 Glacier Deep Archive. For more information, see S3 Glacier storage classes and Storage classes for archiving objects in the Amazon S3 User Guide.

Upload an Archive to a Vault in S3 Glacier by 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 S3 Glacier Region endpoint.

  • The code example uses the US West (Oregon) Region (us-west-2).

  • The example uses the Upload API operation of the ArchiveTransferManager class to upload your archive. For small archives, this operation uploads the archive directly to S3 Glacier. For larger archives, this operation uses the multipart upload API operation in S3 Glacier to split the upload into multiple parts for better error recovery, if any errors are encountered while streaming the data to S3 Glacier.

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

Note

S3 Glacier keeps an inventory of all the archives in your vaults. When you upload the archive in the following example, the archive 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 by Using the High-Level API of the AWS SDK for .NET
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(); } } }