Amazon Simple Storage Service
开发人员指南 (API 版本 2006-03-01)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

使用适用于 .NET 的 AWS 开发工具包在单个操作中复制 Amazon S3 对象

以下 C# 示例演示如何使用高级别适用于 .NET 的 AWS 开发工具包在单个操作中复制最大为 5 GB 的对象。对于大于 5 GB 的对象,请使用使用适用于 .NET 的 AWS 开发工具包分段上传 API 复制 Amazon S3 对象中所述的分段上传复制示例。

此示例将创建最大为 5 GB 的对象的副本。要获得关示例与特定版本的适用于 .NET 的 AWS 开发工具包的兼容性的信息以及有关如何创建和测试有效示例的说明,请参阅运行 Amazon S3 .NET 代码示例

using Amazon.S3; using Amazon.S3.Model; using System; using System.Threading.Tasks; namespace Amazon.DocSamples.S3 { class CopyObjectTest { private const string sourceBucket = "*** provide the name of the bucket with source object ***"; private const string destinationBucket = "*** provide the name of the bucket to copy the object to ***"; private const string objectKey = "*** provide the name of object to copy ***"; private const string destObjectKey = "*** provide the destination object key name ***"; // Specify your bucket region (an example region is shown). private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2; private static IAmazonS3 s3Client; public static void Main() { s3Client = new AmazonS3Client(bucketRegion); Console.WriteLine("Copying an object"); CopyingObjectAsync().Wait(); } private static async Task CopyingObjectAsync() { try { CopyObjectRequest request = new CopyObjectRequest { SourceBucket = sourceBucket, SourceKey = objectKey, DestinationBucket = destinationBucket, DestinationKey = destObjectKey }; CopyObjectResponse response = await s3Client.CopyObjectAsync(request); } catch (AmazonS3Exception e) { Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message); } catch (Exception e) { Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message); } } } }

更多信息

适用于 .NET 的 AWS 开发工具包

本页内容: