将 AbortMultipartUploads 与 AWS SDK 或 CLI 配合使用 - Amazon Simple Storage Service

AbortMultipartUploads 与 AWS SDK 或 CLI 配合使用

以下代码示例显示如何使用 AbortMultipartUploads

.NET
AWS SDK for .NET
注意

查看 GitHub,了解更多信息。例如,如果您将大小为 128 KB 到 1024 KB 的对象设置为从 S3 标准存储类移到 S3标准-IA 存储类,则大小精确为 1024 KB 和 128 KB 的对象将不会转换到 S3 标准-IA。

using System; using System.Threading.Tasks; using Amazon.S3; using Amazon.S3.Transfer; /// <summary> /// This example shows how to use the Amazon Simple Storage Service /// (Amazon S3) to stop a multi-part upload process using the Amazon S3 /// TransferUtility. /// </summary> public class AbortMPU { public static async Task Main() { string bucketName = "doc-example-bucket"; // If the AWS Region defined for your default user is different // from the Region where your Amazon S3 bucket is located, // pass the Region name to the S3 client object's constructor. // For example: RegionEndpoint.USWest2. IAmazonS3 client = new AmazonS3Client(); await AbortMPUAsync(client, bucketName); } /// <summary> /// Cancels the multi-part copy process. /// </summary> /// <param name="client">The initialized client object used to create /// the TransferUtility object.</param> /// <param name="bucketName">The name of the S3 bucket where the /// multi-part copy operation is in progress.</param> public static async Task AbortMPUAsync(IAmazonS3 client, string bucketName) { try { var transferUtility = new TransferUtility(client); // Cancel all in-progress uploads initiated before the specified date. await transferUtility.AbortMultipartUploadsAsync( bucketName, DateTime.Now.AddDays(-7)); } catch (AmazonS3Exception e) { Console.WriteLine($"Error: {e.Message}"); } } }

有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 AWS SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。