public static void AsyncUploadPartCopys(String targetBucket, String targetObject, String sourceBucket, String sourceObject,
                                                String uploadId, int partSize)
        {
            var metadata = client.GetObjectMetadata(sourceBucket, sourceObject);
            var fileSize = metadata.ContentLength;

            var partCount = (int)fileSize / partSize;

            if (fileSize % partSize != 0)
            {
                partCount++;
            }

            var ctx = new UploadPartCopyContext()
            {
                TargetBucket   = targetBucket,
                TargetObject   = targetObject,
                UploadId       = uploadId,
                TotalParts     = partCount,
                CompletedParts = 0,
                SyncLock       = new object(),
                PartETags      = new List <PartETag>(),
                WaitEvent      = new ManualResetEvent(false)
            };

            for (var i = 0; i < partCount; i++)
            {
                var skipBytes = (long)partSize * i;
                var size      = (partSize < fileSize - skipBytes) ? partSize : (fileSize - skipBytes);
                var request   =
                    new UploadPartCopyRequest(targetBucket, targetObject, sourceBucket, sourceObject, uploadId)
                {
                    PartSize   = size,
                    PartNumber = i + 1,
                    BeginIndex = skipBytes
                };
                client.BeginUploadPartCopy(request, UploadPartCopyCallback, new UploadPartCopyContextWrapper(ctx, i + 1));
            }

            ctx.WaitEvent.WaitOne();
        }
Beispiel #2
0
 public UploadPartCopyContextWrapper(UploadPartCopyContext context, int partNumber)
 {
     Context    = context;
     PartNumber = partNumber;
 }