private static void AsyncUploadParts(String bucketName, String objectName, String fileToUpload, String uploadId, int partSize) { var fi = new FileInfo(fileToUpload); var fileSize = fi.Length; var partCount = fileSize / partSize; if (fileSize % partSize != 0) { partCount++; } var ctx = new UploadPartContext() { BucketName = bucketName, ObjectName = objectName, 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 fs = new FileStream(fileToUpload, FileMode.Open, FileAccess.Read, FileShare.Read); var skipBytes = (long)partSize * i; fs.Seek(skipBytes, 0); var size = (partSize < fileSize - skipBytes) ? partSize : (fileSize - skipBytes); var request = new UploadPartRequest(bucketName, objectName, uploadId) { InputStream = fs, PartSize = size, PartNumber = i + 1 }; client.BeginUploadPart(request, UploadPartCallback, new UploadPartContextWrapper(ctx, fs, i + 1)); } ctx.WaitEvent.WaitOne(); }
public UploadPartContextWrapper(UploadPartContext context, Stream partStream, int partNumber) { Context = context; PartStream = partStream; PartNumber = partNumber; }
private static void AsyncUploadParts(String bucketName, String objectName, String fileToUpload, String uploadId, int partSize) { var fi = new FileInfo(fileToUpload); var fileSize = fi.Length; var partCount = fileSize / partSize; if (fileSize % partSize != 0) { partCount++; } var ctx = new UploadPartContext() { BucketName = bucketName, ObjectName = objectName, 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 fs = new FileStream(fileToUpload, FileMode.Open, FileAccess.Read, FileShare.Read); var skipBytes = (long)partSize * i; fs.Seek(skipBytes, 0); var size = (partSize < fileSize - skipBytes) ? partSize : (fileSize - skipBytes); var request = new UploadPartRequest(bucketName, objectName, uploadId) { InputStream = fs, PartSize = size, PartNumber = i + 1 }; _ossClient.BeginUploadPart(request, UploadPartCallback, new UploadPartContextWrapper(ctx, fs, i + 1)); } ctx.WaitEvent.WaitOne(); }